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.
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.
On the single line of the output print the number of groups of magnets.
6101010011010
3
401011010
2
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.
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.
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.
6 51 3 8 14 19 20
3
6 11 3 5 7 9 10
2
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.
#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.
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Write the needed number of flagstones.
6 6 4
4
#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;}
- cccc练习四
- cccc练习一
- cccc练习二
- cccc练习三
- cccc
- cccc
- cccc
- cccc
- cccc
- cccc
- cccc
- cccc
- cccc
- CCCC练习 5-10树的遍历
- CCCC练习 5-11玩转二叉树
- 练习四
- cccc水题
- cccc 朋友圈
- Git在Android Studio上的使用
- UI到底是怎么接受事件的事件
- 高通 MSM8K bootloader : SBL1
- hust 1017 Exact cover
- getContextPath、getServletPath、getRequestURI的区别
- cccc练习四
- eclipse 结构优化
- MySQL事务提交过程(二)
- C++的嵌套类
- 窗口处理大全
- Sublime修改成为Python编辑器,设置系统环境变量
- spring的xml中注册bean的时候报错1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>
- P1339 热浪
- hibernate使用(myeclipse2014)