原题:

  1. Description
  2. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
  3.  
  4. Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
  5.  
  6. Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
  7.  
  8. Input
  9. The first line of the input contains the only integer n (1 ≤ n ≤ 9) the number of digits in the phone number that Mike put in.
  10.  
  11. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
  12.  
  13. Output
  14. If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
  15.  
  16. Otherwise print "NO" (without quotes) in the first line.
  17.  
  18. Sample Input
  19. Input
  20. 3
  21. 586
  22. Output
  23. NO
  24. Input
  25. 2
  26. 09
  27. Output
  28. NO
  29. Input
  30. 9
  31. 123456789
  32. Output
  33. YES
  34. Input
  35. 3
  36. 911
  37. Output
  38. YES

原题

提示:当当前手势可以左移一个或者右、上、下 ,即代表不唯一,输出NO。暴力判断就好,比如包含1,4,7,0 之一的number就是不可以左移的。如果四个方向都不可移动就是YES。

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4.  
  5. using namespace std;
  6.  
  7. #define MAX(x,y) (((x)>(y)) ? (x) : (y))
  8. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  9. #define ABS(x) ((x)>0?(x):-(x))
  10.  
  11. const int inf = 0x7fffffff;
  12. const int N=;
  13. char a[N];
  14. int b[N];
  15.  
  16. int n;
  17.  
  18. bool can_move_left()
  19. {
  20. for(int i=;i<n; i++){
  21. if(b[i]== ||b[i]== ||b[i]== ||b[i]==)
  22. return false;
  23. }
  24. return true;
  25. }
  26.  
  27. bool can_move_right()
  28. {
  29. for(int i=;i<n; i++){
  30. if(b[i]== ||b[i]== ||b[i]== ||b[i]==)
  31. return false;
  32. }
  33. return true;
  34. }
  35.  
  36. bool can_move_up()
  37. {
  38. for(int i=;i<n; i++){
  39. if(b[i]== ||b[i]== ||b[i]==)
  40. return false;
  41. }
  42. return true;
  43. }
  44.  
  45. bool can_move_down()
  46. {
  47. for(int i=;i<n; i++){
  48. if(b[i]== ||b[i]== ||b[i]==)
  49. return false;
  50. }
  51. return true;
  52. }
  53.  
  54. int main()
  55. {
  56.  
  57. cin>>n;
  58. scanf("%s",a);
  59. for(int i=; i<n; i++){
  60. b[i]=a[i]-''+;
  61. }
  62.  
  63. int ok=;
  64. if(ok == ){
  65. if(can_move_left()) ok=;
  66. }
  67. if(ok == ){
  68. if(can_move_right()) ok=;
  69. }
  70. if(ok == ){
  71. if(can_move_up()) ok=;
  72. }
  73. if(ok == ){
  74. if(can_move_down()) ok=;
  75. }
  76.  
  77. printf("%s\n",ok? "NO":"YES");
  78.  
  79. return ;
  80. }

codeforces 361 A - Mike and Cellphone的更多相关文章

  1. codeforces 689A A. Mike and Cellphone(水题)

    题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. codeforces 361 E - Mike and Geometry Problem

    原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him ...

  3. codeforces 361 B - Mike and Shortcuts

    原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going t ...

  4. codeforces 361 C - Mike and Chocolate Thieves

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad ...

  5. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  6. Codeforces Round #361 (Div. 2)A. Mike and Cellphone

    A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. CodeForces 689A Mike and Cellphone (模拟+水题)

    Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...

  8. A. Mike and Cellphone(Round 361 Div.2)

    写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...

  9. 套题 codeforces 361

    A题((Mike and Cellphone) 看起来好像需要模拟数字键位的运动,可是,只要判断出那些必然YES的数字组合不就好了么 #include <cstdio> #include ...

随机推荐

  1. 如何让LinearLayout也有类似Button的点击效果?

    有的时候,我们希望LinearLayout布局也有点击的效果,这时候我们不仅需要一个作为背景的selector,还要设置一些其它属性才行: android:clickable="true&q ...

  2. Flash Builder如何自定义工作目录

    熟悉了myeclipse可以自定义目录的设置,今天在使用flash builder 时,当导入一个工程到现有项目空间 选择根目录,点击浏览的时候出现的目录是C:\Users\Administrator ...

  3. linux php redis扩展的安装和redis服务的安装

    一.php redis扩展的安装 wget http://pecl.php.net/get/redis-2.2.7.tgztar zvxf redis-2.2.7.tgzcd redis-2.2.7/ ...

  4. SpringMVC案例1——对User表进行CRUD操作

    ------------------------------------------------------------------web.xml--------------------------- ...

  5. javac

    http://openjdk.java.net/groups/compiler/ http://crazyjavahacking.org/tag/javac/ http://openjdk.java. ...

  6. Docker SSH

    1. Dockerfile   -->docker build -t centos6-ssh https://git.oschina.net/feedao/Docker_shell/raw/st ...

  7. Windows 2003上 SaltStack/Salt 和 psutil 可能存在的问题及解决

    今天把salt安装在windows 2003上,发现无法启动,随之而来的是一个有一个的坑,让我们一起逐个排查. 问题一(salt无法启动) salt无法启动,错误结果如图:

  8. Excel中如何提取字符串中的数字

    取字符串中的数字,假如数据在A列,提取公式为 =LOOKUP(9^9,--MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&5^19)),ROW($1:$99) ...

  9. ubuntu14升级到15后遇到的问题

    ubuntu14的unity坏了,于是就找了个镜像升级到15.但是升级完android开发环境出了点问题.. 1:Picked up JAVA_TOOL_OPTIONS: -javaagent:/us ...

  10. mysql中in和exists二者的区别和性能影响

    mysql查询语句in和exists二者的区别和性能影响 还记得一次面试中被人问到in 和 exists的区别,当然只是草草做答,现在来做下分析. mysql中的in语句是把外表和内表作hash 连接 ...