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函数写法:
 #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

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代码:
 #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

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代码:
 #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 ;
}

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

  1. Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)

    题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...

  2. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

  3. Codeforces Round #177 (Div. 2) B. Polo the Penguin and Matrix (贪心,数学)

    题意:给你一个\(n\)x\(m\)的矩阵,可以对矩阵的所有元素进行\(\pm d\),问能否使得所有元素相等. 题解:我们可以直接记录一个\(n*m\)的数组存入所有数,所以\((a_1+xd)=( ...

  4. 贪心 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx, 接下来mx次循环,若是0,输出0:若是1,输出1,s[j]--: 注意:之前的0的要忽略 */ #inc ...

  5. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  6. Codeforces Round #519 by Botan Investments(前五题题解)

    开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...

  7. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  8. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  9. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  10. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

随机推荐

  1. Linux 文件API

    9/19/2017  开始攻读<LinuxC编程实战>,这是相关的笔记 1.创建 int creat(const char *filename, mode_t mode); 参数mode指 ...

  2. AntData.ORM框架 之 读写分离

    环境准备 准备2台机器配置好Master Slaver模式 我是用vmware 2台虚拟机配置的.有需要请联系. Master:192.168.11.130 Slaver:192.168.11.133 ...

  3. ArcGIS 网络分析[4] 网络数据集深入浅出之连通性、网络数据集的属性及转弯要素

    前面介绍完了如何创建网络数据集.如何使用网络分析功能,当然还有的读者会迷惑于一些更深层次的问题,比如网络数据集的连通性问题等. 因为不可能面面俱到,我只能挑重点来阐述,我觉得网络数据集的连通性.属性和 ...

  4. IT小白学习Discuz!框架(一)

    1.Discuz!是什么? 答:(1).Crossday Discuz! Board(简称 Discuz!)是北京康盛新创科技有限责任公司推出的一套通用的社区论坛软件系统. (2).Crossday ...

  5. php 理解

    <?php class t { var $num; var $dynamic_function; public function dynamic_function() { $func = $th ...

  6. windows 运行banana

    1 git clone 工程 2 安装 npm 3 执行 npm install -g bower

  7. NPOI 2.0 教程

    NPOI2.0帮助官方地址 目录 1. 前言 1.1 NPOI 2.0与NPOI 1.x的区别 1.2 NPOI 2.0模块简介 1.3 自动识别并打开Excel 2003和Excel 2007文件 ...

  8. Node.js 蚕食计划(五)—— Koa 基础项目搭建

    Koa 是由 Express 原班人马打造的超轻量服务端框架 与 Express 相比,除了自由度更高,可以自行引入中间件之外,更重要的是使用了 ES6 + async,从而避免了回调地狱 不过也是因 ...

  9. Laravel 中实现是否关注

    @if ($user->id !== Auth::user()->id) <div id="follow_form"> @if (Auth::user()- ...

  10. 浏览器根对象window之screen

    1. screen 1.1 availHeight/Width screen.availWidth返回浏览器窗口可占用的水平宽度(单位:像素). screen.availHeight返回浏览器窗口在屏 ...