【打CF,学算法——二星级】CodeForces 689A Mike and Cellphone (模拟)
来源:互联网 发布:出版行业 知乎 编辑:程序博客网 时间:2024/05/17 13:43
【CF简介】
提交链接:CF 689A
题面:
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.
题意:
给定一个0-9数字键盘,随后输入一个操作序列,问该操作序列在键盘上形成的手势是否是唯一的,是YES,否NO。
解题:
可以先记录初始点的位置,随后序列的位置都与该点作差,形成一个位置偏差序列。然后,暴力以0-9的位置都作为起始点开始,按照移动序列行走,若能全部走完,则计数值+1。最后看计数值是否唯一,唯一则为YES,不唯一为NO。
代码:
#include <iostream>#include <vector>#include <cstdio>#include <cstring>using namespace std;int x[10]={3,0,0,0,1,1,1,2,2,2},y[10]={1,0,1,2,0,1,2,0,1,2};bool vis[4][3];int main(){vector <int> vx,vy; int n,px,py,cnt=0;bool flag;string s;cin>>n>>s;memset(vis,-1,sizeof(vis));vis[3][0]=0;vis[3][2]=0;px=x[s[0]-'0'];py=y[s[0]-'0'];vx.push_back(0);vy.push_back(0);for(int i=1;i<s.length();i++){ vx.push_back(x[s[i]-'0']-px);vy.push_back(y[s[i]-'0']-py);}for(int i=0;i<10;i++){flag=1;for(int j=0;j<n;j++){px=x[i]+vx[j];py=y[i]+vy[j];if(px>=0&&px<=3&&py>=0&&py<=2&&vis[px][py]) continue;else{flag=0;break;}}if(flag)cnt++;}if(cnt>1)printf("NO\n");elseprintf("YES\n");return 0;}
- 【打CF,学算法——二星级】CodeForces 689A Mike and Cellphone (模拟)
- 【打CF,学算法——二星级】CodeForces 292A SMSC (模拟)
- codeforces 689A Mike and Cellphone(模拟)
- 【打CF,学算法——二星级】Codeforces Round #312 (Div. 2) A Lala Land and Apple Trees
- 【打CF,学算法——二星级】CodeForces 374A Inna and Pink Pony (水题/坑题)
- 【打CF,学算法——二星级】Codeforces 584C Marina and Vasya (简单构造)
- 【打CF,学算法——二星级】CodeForces 282C XOR and OR (观察)
- 【打CF,学算法——二星级】Codeforces 703B Mishka and trip (统计)
- 【打CF,学算法——三星级】CodeForces 689C Mike and Chocolate Thieves (二分)
- Codeforces 689A. Mike and Cellphone(模拟)
- 【打CF,学算法——二星级】Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- 【打CF,学算法——一星级】CodeForces 318A (水题)
- 【打CF,学算法——一星级】CodeForces 74A Room Leader (水题)
- 【打CF,学算法——一星级】Codeforces 699A Launch of Collider (水题)
- 【打CF,学算法——一星级】CodeForces 701A Cards(水题)
- 【打CF,学算法——一星级】Codeforces 705A Hulk
- CodeForces 689A Mike and Cellphone
- Codeforces-689A-Mike and Cellphone
- 7. Reverse Integer
- RTL8723BU WiFi—蓝牙 模块移植
- SQLite数据库(下)
- 网站
- iOS-获取手机健康步数,去除人为添加的数据
- 【打CF,学算法——二星级】CodeForces 689A Mike and Cellphone (模拟)
- 孩子教育,不要只看重分数!
- udp传输文件的服务器端
- iOS-最全的App上架教程
- Android 2016新技术
- Linux是这样泄露内存的:Linux内存泄露过程观察
- ASP.NET MVC3
- cocoaPods使用中遇到的问题
- Unmarshalling Error: unexpected element 错误的解决