Codeforces Beta Round #77 (Div. 2 Only)——A,B,C
来源:互联网 发布:淘宝上的谭光树蜂蜜 编辑:程序博客网 时间:2024/06/10 07:08
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
水题,判断有没有连续的7个或7个以上的0或1即可。
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744,474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to n.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
解答:生成只有4,7的排列,放进向量中进行排序,用lower_bound函数选出大于等于该数的第一个位置即可。
#include <iostream>#include <vector>#include <sstream>#include <algorithm>using namespace std;int main(){ long long n; cin>>n; vector<long long> v; for(int i=1;i<=8;i++) { string a=string(i,'4')+string(i,'7'); do { stringstream ss(a); long long t; ss>>t; v.push_back(t); }while(next_permutation(a.begin(),a.end())); } sort(v.begin(),v.end()); cout<<*lower_bound(v.begin(),v.end(),n)<<endl; return 0;}
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r]is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i)aj = bj. |a| stands for the length of string a.
分析:要给定的letter字母尽可能的多,对于不是letter的所有字母变成letter.对于是letter的字母如果是字母a那么只能变成字母b否则变成字母a即可满足字典序最小。
#include <iostream>#include <cstring>#include <algorithm>#include <string>using namespace std;const int maxn=100+5;string s[maxn],sa[maxn],w,wa;bool m[maxn];char letter;string To(string s){ for(int i=0;i<s.length();i++) if(s[i]>='A'&&s[i]<='Z') s[i]+=32; return s;}int main(){ int n; cin>>n; for(int i=0;i<n;i++){cin>>s[i];sa[i]=To(s[i]);} cin>>w>>letter; wa=To(w); int l=wa.length(); memset(m,0,sizeof(m)); for(int i=0;i<wa.length();i++) for(int k=0;k<n;k++) if(l-s[k].length()+1>=i&&wa.substr(i,sa[k].length())==sa[k]) for(int j=i;j<i+sa[k].length();j++) m[j]=1; if(letter>='A'&&letter<='Z') letter+=32; for(int i=0;i<l;i++) if(m[i]) { if(wa[i]==letter) { char tmp; if(wa[i]=='a') tmp='b'; else tmp='a'; if(w[i]>='A'&&w[i]<='Z') w[i]=tmp-32; else w[i]=tmp; } else if(w[i]>='A'&&w[i]<='Z') w[i]=letter-32; else w[i]=letter; } cout<<w<<endl; return 0;}
- Codeforces Beta Round #77 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #72 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #73 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #76 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #93 (Div. 2 Only)——B
- Codeforces Beta Round #91 (Div. 2 Only)——B
- Codeforces Beta Round #18 (Div. 2 Only)——B
- Codeforces Beta Round #69 (Div. 2 Only)——A,B,D
- Codeforces Beta Round #18 (Div. 2 Only)——A
- Codeforces Beta Round #16 (Div. 2 Only)——C
- Codeforces Beta Round #18 (Div. 2 Only)——C
- Codeforces Beta Round #74 (Div. 2 Only)——C
- Codeforces Beta Round #77 (Div. 2 Only) A题
- Codeforces Beta Round #65 (Div. 2)——A,B,C
- Codeforces Beta Round #67 (Div. 2)——A,B,C
- Codeforces Beta Round #70 (Div. 2)——A,B,C
- Codeforces Beta Round #95 (Div. 2) A B C E
- Codeforces Beta Round #75 (Div. 2 Only)——D
- Ubuntu 12.04中文输入法的安装
- [转]Android xmlns 的作用及其自定义
- 使用ASP.NET上传图片汇总
- 双链表的插入删除操作
- LA_3602DNA Consensus String ( hash, 貪心 )
- Codeforces Beta Round #77 (Div. 2 Only)——A,B,C
- C# using关键字
- IOS 之Google Analytics SDK预研
- 设计 布局管理+封装
- python 字符串模板用法string.Template
- Linux下好用的命令行拍照程序camshot
- 小波稀疏化
- js入门(1)——复制 [ Array对象的slice()和 String对象的substr(),substring() ]
- ubuntu_文件操作