cccc练习四

来源:互联网 发布:网络情人 吴玉龙 铃声 编辑:程序博客网 时间:2024/05/21 09:38

这次练习题的难易程度不是按顺序来的,这就要你有辨别能力,废话不多说,看题,,,

第一题

第二题

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.

Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.

Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Thenn lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put thei-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

Output

On the single line of the output print the number of groups of magnets.

Example
Input
6101010011010
Output
3
Input
401011010
Output
2
Note

The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.

The second testcase has two groups, each consisting of two magnets.

这题挺简单的,就是找一下连续相同的数有多少组。

#include<cstdio>int aa[100005];int main(){    int n,sum;    while(scanf("%d",&n)!=EOF)    {    for(int i=0;i<n;i++)        scanf("%d",&aa[i]);    sum=1;    for(int i=1;i<n;i++)    {    if(aa[i]!=aa[i-1])        sum++;}printf("%d\n",sum);}return 0;}
第三题

第四题

第五题

ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!

More formally, if you typed a word at second a and then the next word at secondb, then if b - a ≤ c, just the new word is appended to other words on the screen. Ifb - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.

For example, if c = 5 and you typed words at seconds1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second20, one more word is typed, and a total of 3 words remain on the screen.

You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

Input

The first line contains two integers n andc (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively.

The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed thei-th word.

Output

Print a single positive integer, the number of words that remain on the screen after alln words was typed, in other words, at the secondtn.

Example
Input
6 51 3 8 14 19 20
Output
3
Input
6 11 3 5 7 9 10
Output
2
Note

The first sample is already explained in the problem statement.

For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second10, so there will be two words on the screen, as the old word won't disappear because10 - 9 ≤ 1.

这题的题意是前后两个数如果大于给定的一个数,则b(不包括b)前面的数全部消失,统计最后剩余的数字数。

#include<cstdio>int aa[100005];int main(){    int n,c,sum;    while(scanf("%d%d",&n,&c)!=EOF)    {    for(int i=0;i<n;i++)        scanf("%d",&aa[i]);    sum=1;    for(int i=1;i<n;i++)    {    if(aa[i]-aa[i-1]<=c)       sum++;    else       sum=1;}printf("%d\n",sum);}return 0;}
第六题

第七题

第八题

第九题

第十题

十一题

Theatre Square in the capital city of Berland has a rectangular shape with the sizen × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the sizea × a.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

Input

The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Example
Input
6 6 4
Output
4
超级简单,不想说啥了,简单的太简单,难的又很难做出,ac之路不好走啊。。。
#include<cstdio>int main(){    long long n,m,n1,m1,a,sum;    while(scanf("%I64d%I64d%I64d",&n,&m,&a)!=EOF)    {    n1=n/a;    m1=m/a;    if(n%a!=0) n1+=1;    if(m%a!=0) m1+=1;sum=n1*m1;printf("%I64d\n",sum);}return 0;}



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 户口转到西安后医保怎么办 上海医保卡掉了怎么办 上海医保本丢了怎么办? 新版医保卡丢了怎么办 武汉社保卡掉了怎么办 职工社保卡丢了怎么办 杭州社保卡丢了怎么办 农村医疗卡丢了怎么办 陕西省医保卡丢了怎么办 小孩社保卡掉了怎么办 社区医保本丢了怎么办 宝宝医保卡掉了怎么办 同煤医疗卡丢了怎么办 杭州医保卡丢了怎么办 新的医保卡丢了怎么办 二代医保卡丢了怎么办 老医保卡丢了怎么办 上海医保卡余额用完了怎么办 身份证丢了医疗报销怎么办 取公积金身份证丢了怎么办 身份证丢了怎么办就诊卡 人在外地怎么办农村社保卡 武汉医保卡丢了怎么办 济宁社保卡丢了怎么办 农村医疗本丢了怎么办 常熟医保卡丢了怎么办 农民社保卡丢了怎么办 常熟社保卡坏了怎么办 社保卡丢失补办期看病怎么办 社保卡补办期间看病怎么办 医保卡冻结了出院结算怎么办 住院医保卡钱不够怎么办 住院押金条丢了怎么办 急用新社保卡要怎么办 看病没带社保卡怎么办 医保卡掉了住院怎么办 厦门医保卡丢了怎么办 成都医保卡丢了怎么办 长春医保卡丢了怎么办 县城医保卡丢了怎么办 医保卡丢了怎么办南宁