Codeforces Beta Round #77 (Div. 2 Only)——A,B,C

来源:互联网 发布:淘宝上的谭光树蜂蜜 编辑:程序博客网 时间:2024/06/10 07:08
A. Football
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

Print "YES" if the situation is dangerous. Otherwise, print "NO".

水题,判断有没有连续的7个或7个以上的0或1即可。

B. Lucky Numbers (easy)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 477444 are lucky and 517467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 477744,474477 are super lucky and 4744467 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.

Input

The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes.

Output

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,且4,7数量相等的最小数字。

解答:生成只有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;}

C. Hockey
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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

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.

题意:对给定串w与所给s串进行匹配,如果相同,w串中的对应的所有字母要进行变化。匹配时不考虑大小写。要求得到所给letter字母最多而且字典序最小的串。

分析:要给定的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;}


原创粉丝点击