Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)

A. Cutting Banner

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

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.

Output

Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).

Examples
Input
CODEWAITFORITFORCES
Output
YES
Input
BOTTOMCODER
Output
NO
Input
DECODEFORCES
Output
YES
Input
DOGEFORCES
Output
NO
               
题目链接:http://codeforces.com/contest/538/problem/A
分析:字符串截取,只能截取一次,可以截取开头,中间,结尾任意一部分,使得最后剩余部分构成单词CODEFORCES,能的话输出YES!
这里我给出两种写法仅供参考!
strncmp函数写法:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char s[105];
 4 char p[]={"CODEFORCES"};
 5 int main()
 6 {
 7     cin>>s;
 8     int j=0;
 9     int len=strlen(s);
10     for(int i=0;i<len;i++)
11     {
12         if(s[i]==p[j])
13             j++;
14         else break;
15     }
16     if(strncmp(s,p,10)==0||strncmp(s+len-10,p,10)==0||strncmp(s+len-10+j,p+j,10)==0)
17     {
18         printf("YES\n");
19         return 0;
20     }
21     printf("NO\n");
22     return 0;
23 }

substr函数写法:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     string s;
 6     cin>>s;
 7     for(int i=0;i<s.length();i++)
 8     {
 9         for(int j=0;j<s.length();j++)
10         {
11             if(s.substr(0,i)+s.substr(j+1)=="CODEFORCES")
12             {
13                 printf("YES\n");
14                 return 0;
15             }
16         }
17     }
18     printf("NO\n");
19     return 0;
20 }

如果还有其它方法欢迎私信我!QAQ

B. Quasi Binary

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

The first line contains a single integer n (1 ≤ n ≤ 106).

Output

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.

Examples
Input
9
Output
9 
1 1 1 1 1 1 1 1 1
Input
32
Output
3 
10 11 11
题目链接:http://codeforces.com/contest/538/problem/B
分析:  任意一个数可以由10个以内的数相加,简单来讲,就是找出这个数中数字最大的那一个,45624出现最大的数是6,所以这个数必须6个数组成!
下面给出AC代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     int s[11];
 7     int k=1,maxn=0;
 8     memset(s,0,sizeof(s));
 9     cin>>n;
10     while(n)
11     {
12         int a=n%10;
13         n/=10;
14         maxn=max(maxn,a);
15         for(int i=1;i<=a;i++)
16             s[i]+=k;
17         k*=10;
18     }
19     cout<<maxn<<endl;
20     for(int i=1;i<maxn;i++)
21         cout<<s[i]<<" ";
22     cout<<s[maxn]<<endl;
23     return 0;
24 }

C. Tourist's Notes

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

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.

Output

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).

Examples
Input
8 2 
2 0
7 0
Output
2
Input
8 3 
2 0
7 0
8 3
Output
IMPOSSIBLE
Note

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
题意:一个旅行者在外旅行n天,第i天所在地方的海拔为hi,相邻两天的海拔之差不超过1。给出部分天数的海拔,问这个人在这n天中,所到地方的最高海拔是多少?如果根据给出的数据不符合题意描述,即出现相邻两天的海拔之差超过1,输出“IMPOSSIBLE”。
分析:
贪心求解,不过要注意第一天的高度是任意的!
下面给出AC代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=100010;
 4 int n,m;
 5 int d[N],h[N];
 6 int main()
 7 {
 8     cin>>n>>m;
 9     for(int i=1;i<=m;i++)
10         scanf("%d%d",&d[i],&h[i]);
11     int maxn=0;
12     for(int i=2;i<=m;i++)
13     {
14         int dd=d[i]-d[i-1]-1;
15         int hh=abs(h[i]-h[i-1]);
16         if(dd-hh<-1)//d相差0,但是高度可以相差1,所以是-1
17         {
18             cout<<"IMPOSSIBLE"<<endl;
19             return 0;
20         }
21         maxn=max(maxn,max(h[i],h[i-1])+((dd-hh)+1)/2);
22     }
23     maxn=max(maxn,n-d[m]+h[m]);//最后一天可以到达的高度
24     maxn=max(maxn,d[1]-1+h[1]);//第一天可以到达的高度
25     cout<<maxn<<endl;
26     return 0;
27 }

 

      
       

           

           

posted @ 2017-05-18 16:58  Angel_Kitty  阅读(177)  评论(0编辑  收藏  举报