Codeforces Round #361 (Div. 2) -- A. Mike and Cellphone (思路题目)
来源:互联网 发布:java工作描述怎么写 编辑:程序博客网 时间:2024/05/29 10:12
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:
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 considerfinger 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":
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?
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.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
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.
Otherwise print "NO" (without quotes) in the first line.
3586
NO
209
NO
9123456789
YES
3911
YES
You can find the picture clarifying the first sample case in the statement above.
大体题意:
图形类似于图形密码,输入一个图形密码,问是否存在另一个图形密码,路径与之完全相同!
思路:
思路题目,比赛期间写了很久也没写出来就睡觉了~~ 第二天才发现 A的人好少~ 还需多练习呀~
借鉴的别人的代码:
设置四个变量 初始化为1 ,表示左边 右边 上边 下边是否可以挪动!
当选择了1 2 3 时,上面不可以走 up = 0
当选择了 3 6 9 右面不可以走 right = 0
当选择了1 4 7 时 左边不可以走 left = 0
当选择了7 9 时 下面不可以走 down = 0
当选择了0 下面 左边 右边 都不可以走 down = left = right = 0;
最后看看只要有一个方向可以走,就是NO 否则是YES!
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 100 + 10;char s[maxn];int main(){ int n; while(scanf("%d",&n) == 1){ scanf("%s",s); int left = 1,right = 1,up = 1,down = 1; for (int i = 0; i < n; ++i){ char ch = s[i]; if (ch == '1' || ch == '2' || ch == '3')up = 0; if (ch == '3' || ch == '6' || ch == '9')right = 0; if (ch == '1' || ch == '4' || ch == '7')left = 0; if (ch == '7' || ch == '9')down = 0; if (ch == '0')left = right = down = 0; } if (left || right || down || up)printf("NO\n"); else printf("YES\n"); } return 0;}
- Codeforces Round #361 (Div. 2) -- A. Mike and Cellphone (思路题目)
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone
- Codeforces Round #361 (Div. 2)A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone ( 模拟 )
- Codeforces Round #361 (Div.2) - A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) 689A Mike and Cellphone
- Codeforces 689A. Mike and Cellphone(模拟)
- CodeForces 689A Mike and Cellphone
- codeforces 689A Mike and Cellphone(模拟)
- Codeforces-689A-Mike and Cellphone
- Codeforces Round #305 (Div. 2) A. Mike and Fax
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2)--A. Mike and Fax
- Codeforces Round #305 (Div. 2)A. Mike and Fax
- Codeforces Round #410 (Div. 2)-A. Mike and palindrome-思维
- Codeforces Round #410 (Div.2) A.Mike and palindrome-模拟
- USB调试实现
- JAVA自学之每日一题(六)
- springmvc导入导出
- 虚幻4蓝图使用小技巧(更新)
- poj 1840 哈希+离散化
- Codeforces Round #361 (Div. 2) -- A. Mike and Cellphone (思路题目)
- 经常逛的网站,持续更新
- 解决Mac AndroidStudio无法关联源码问题
- 关于Fragment的一点小技巧
- Android_将RecyclerView打造成自己SwipeRecyclerView
- Android中线程同步之Mutex与Condtion的用法
- 教你快速掌握androidstudio使用git上传本地项目到github、版本控制
- 正则表达式学习笔记(一)全部符号解释
- 画折线