Codeforces Round #361 (Div. 2) A
2016-07-10 09:23
239 查看
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.
题意:判断一组手势的顺序(0~9数字可以重复)长度最多为9是否是唯一的 如果唯一则输出YES 否则NO
题解:首先判断给出的手势顺序的坐在区域上下左右界
细细考虑可以判断当上界为1下界为4时,可以唯一确定
当手势区域为3*3时并且下界为3,序列中存在7或9时可以唯一确定序列...
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.
题意:判断一组手势的顺序(0~9数字可以重复)长度最多为9是否是唯一的 如果唯一则输出YES 否则NO
题解:首先判断给出的手势顺序的坐在区域上下左右界
细细考虑可以判断当上界为1下界为4时,可以唯一确定
当手势区域为3*3时并且下界为3,序列中存在7或9时可以唯一确定序列...
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int n; char a[15]; int b[15]; int u,d,l,r; int main() { scanf("%d",&n); cin>>a; u=10; d=0; l=10; r=0; int flag=0; for(int i=0;i<n;i++) b[i]=a[i]-'0'; for(int i=0;i<n;i++) { if(b[i]==7||b[i]==9) flag=1; if(b[i]==1||b[i]==2||b[i]==3) { u=min(u,1); d=max(d,1); } if(b[i]==4||b[i]==5||b[i]==6) { u=min(u,2); d=max(d,2); } if(b[i]==7||b[i]==8||b[i]==9) { u=min(u,3); d=max(d,3); } if(b[i]==1||b[i]==4||b[i]==7) { l=min(l,1); r=max(r,1); } if(b[i]==2||b[i]==5||b[i]==8) { l=min(l,2); r=max(r,2); } if(b[i]==3||b[i]==6||b[i]==9) { l=min(l,3); r=max(r,3); } if(b[i]==0) { l=min(l,2); r=max(r,2); u=min(u,4); d=max(d,4); } } //cout<<u<<" "<<d<<" "<<l<<" "<<r<<endl; if(d-u==2&&r-l==2&&d==3&&flag==1) { cout<<"YES"<<endl; } else { if(d-u==3) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- 快速解决tomcat指定的服务未安装问题
- LeetCode - 213. House Robber II
- Xenia and Weights codeforces 339c(记忆化搜索dfs)
- D - Lowest Bit
- c#新手入门级代码分享 输出枚举类型中所有成员的名称
- c#新手入门级代码分享 枚举类型。输出数值所对应的变量名称
- Systemd 入门教程:实战篇
- 用Javascript遍历控件
- scala+play+slick + mysql
- c#新手入门级代码分享 隐式声明一维int型数组,并遍历输出
- highcharts饼图动态显示数据(用ajax)
- UVA-455 Periodic Strings
- Android 隐式Intent相比于显式Intent的优点
- centos7和centos6的区别
- 扁平化设计技巧
- Hadoop算法机制---倒排索引详解
- 使用脚本来提高工作效率
- 我们聊聊快排吧...
- c#新手入门级代码分享 getlength方法的到一个三维数组的页,行,列
- postgresql----文本搜索类型和检索函数