Codeforces Round #361 (Div. 2)A. Mike and Cellphone
2016-07-07 23:12
344 查看
A. Mike and Cellphone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 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":
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?
Input
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.
Output
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.
Examples
input
output
input
output
input
output
input
output
Note
You can find the picture clarifying the first sample case in the statement above.
直接暴力模拟。
记录一下状态,然后暴力枚举每一个位置,看看有几个位置满足那个状态,如果答案数大于1 那么他就有可能播错电话。..
ccf上有一个类似的..我是不是在做广告...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 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":
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?
Input
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.
Output
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.
Examples
input
3 586
output
NO
input
2 09
output
NO
input
9 123456789
output
YES
input
3 911
output
YES
Note
You can find the picture clarifying the first sample case in the statement above.
直接暴力模拟。
记录一下状态,然后暴力枚举每一个位置,看看有几个位置满足那个状态,如果答案数大于1 那么他就有可能播错电话。..
ccf上有一个类似的..我是不是在做广告...
/* *********************************************** Author :guanjun Created Time :2016/7/7 22:40:13 File Name :cf361.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10010 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std;int a[maxn]; int b[4][3]={ 1,2,3, 4,5,6, 7,8,9, INF,0,INF }; map<int,pair<int,int> >mp; int main() { int n; string s; cin>>n; cin>>s; for(int i=0;i<n;i++){ a[i+1]=s[i]-'0'; } for(int i=0;i<4;i++){ for(int j=0;j<3;j++){ mp[b[i][j]]={i,j}; } } vector<pair<int,int> >v; int t=1; for(int i=2;i<=n;i++){ int x=mp[a[i]].first-mp[a[t]].first; int y=mp[a[i]].second-mp[a[t]].second; v.push_back({x,y}); t=i; } int ans=0; int m=v.size();for(int i=0;i<4;i++){ for(int j=0;j<3;j++){ if(b[i][j]==INF)continue; int k; int ox=i; int oy=j; for(k=0;k<m;k++){ int x=ox+v[k].first; int y=oy+v[k].second; if(x>=4||y>=3||x<0||y<0)break; if(b[x][y]==INF)break; ox=x; oy=y; } if(k==m)ans++; } } if(ans>1)puts("NO"); else puts("YES"); return 0; }
相关文章推荐
- KVC 与 KVO 理解-b
- 关于java数据类型的自己的见解
- 7月6日实习
- 大数据分布式计算--hadoop
- Poj1386 Play on Words
- 区块链开发(一)搭建基于以太坊的私有链环境
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别-b
- 【javascript]-Dom的编辑
- 《一个普通IT人的十年回顾》金旭亮——警醒自己!
- java I/O流(4) RandomAccessFile
- Git的相关用法
- CSS样式表
- python总结
- linux DVB 驱动分析
- Android 获取文字的高度
- 使用maven一步一步构建spring mvc项目
- BZOJ4118 : [Wf2015]Window Manager
- SCU2016-02 R题概率dp
- 编译原理-LR(0)分析法
- 图像视觉博客资源