A. Cutting Banner
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
CODEWAITFORITFORCES
YES
BOTTOMCODER
NO
DECODEFORCES
YES
DOGEFORCES
NO
题目链接:http://codeforces.com/contest/538/problem/A
#include <bits/stdc++.h>
using namespace std;
char s[];
char p[]={"CODEFORCES"};
int main()
{
cin>>s;
int j=;
int len=strlen(s);
for(int i=;i<len;i++)
{
if(s[i]==p[j])
j++;
else break;
}
if(strncmp(s,p,)==||strncmp(s+len-,p,)==||strncmp(s+len-+j,p+j,)==)
{
printf("YES\n");
return ;
}
printf("NO\n");
return ;
}
substr函数写法:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=;i<s.length();i++)
{
for(int j=;j<s.length();j++)
{
if(s.substr(,i)+s.substr(j+)=="CODEFORCES")
{
printf("YES\n");
return ;
}
}
}
printf("NO\n");
return ;
}
如果还有其它方法欢迎私信我!QAQ
B. Quasi Binary
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer n (1 ≤ n ≤ 106).
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
9
9
1 1 1 1 1 1 1 1 1
32
3
10 11 11
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
int s[];
int k=,maxn=;
memset(s,,sizeof(s));
cin>>n;
while(n)
{
int a=n%;
n/=;
maxn=max(maxn,a);
for(int i=;i<=a;i++)
s[i]+=k;
k*=;
}
cout<<maxn<<endl;
for(int i=;i<maxn;i++)
cout<<s[i]<<" ";
cout<<s[maxn]<<endl;
return ;
}
C. Tourist's Notes
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all i's from 1 to n - 1 the inequality |hi - hi + 1| ≤ 1 holds.
At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |hi - hi + 1| ≤ 1.
The first line contains two space-separated numbers, n and m (1 ≤ n ≤ 108, 1 ≤ m ≤ 105) — the number of days of the hike and the number of notes left in the journal.
Next m lines contain two space-separated integers di and hdi (1 ≤ di ≤ n, 0 ≤ hdi ≤ 108) — the number of the day when the i-th note was made and height on the di-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all i from 1 to m - 1 the following condition holds: di < di + 1.
If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes).
8 2
2 0
7 0
2
8 3
2 0
7 0
8 3
IMPOSSIBLE
For the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).
In the second sample the inequality between h7 and h8 does not hold, thus the information is inconsistent.
题目链接:http://codeforces.com/contest/538/problem/C
#include <bits/stdc++.h>
using namespace std;
const int N=;
int n,m;
int d[N],h[N];
int main()
{
cin>>n>>m;
for(int i=;i<=m;i++)
scanf("%d%d",&d[i],&h[i]);
int maxn=;
for(int i=;i<=m;i++)
{
int dd=d[i]-d[i-]-;
int hh=abs(h[i]-h[i-]);
if(dd-hh<-)//d相差0,但是高度可以相差1,所以是-1
{
cout<<"IMPOSSIBLE"<<endl;
return ;
}
maxn=max(maxn,max(h[i],h[i-])+((dd-hh)+)/);
}
maxn=max(maxn,n-d[m]+h[m]);//最后一天可以到达的高度
maxn=max(maxn,d[]-+h[]);//第一天可以到达的高度
cout<<maxn<<endl;
return ;
}