Codeforces Round #361 (Div. 2) A. Mike and Cellphone
2016-07-07 08:41
218 查看
原题链接
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
记录在每个数字的位置能够移动的方向。然后给定输入,判断是否所有的数字都能向同一个方向移动。
#include <bits/stdc++.h>
using namespace std;
int k[10][4] = {
{0, 1, 0, 0},
{0, 0, 1, 1},
{1, 0, 1, 1},
{1, 0, 0, 1},
{0, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 0, 1},
{0, 1, 1, 0},
{1, 1, 1, 1},
{1, 1, 0, 0}
};
char s[20];
int main(){
int n;
scanf("%d%s", &n, s);
for(int j = 0; j < 4; j++){
int i;
for(i = 0; i < n; i++){
int d = s[i] - '0';
if(k[d][j] == 0)
break;
}
if(i == n){
puts("NO");
return 0;
}
}
puts("YES");
return 0;
}
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
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
记录在每个数字的位置能够移动的方向。然后给定输入,判断是否所有的数字都能向同一个方向移动。
#include <bits/stdc++.h>
using namespace std;
int k[10][4] = {
{0, 1, 0, 0},
{0, 0, 1, 1},
{1, 0, 1, 1},
{1, 0, 0, 1},
{0, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 0, 1},
{0, 1, 1, 0},
{1, 1, 1, 1},
{1, 1, 0, 0}
};
char s[20];
int main(){
int n;
scanf("%d%s", &n, s);
for(int j = 0; j < 4; j++){
int i;
for(i = 0; i < n; i++){
int d = s[i] - '0';
if(k[d][j] == 0)
break;
}
if(i == n){
puts("NO");
return 0;
}
}
puts("YES");
return 0;
}
相关文章推荐
- 编译原理实验---词法分析
- AAA是Authentication(认证)配置
- gitlab加入sshkey
- 勾股定理一日一证连载45
- Visitor模式详解--设计模式(20)
- css命名规则
- 针对苹果最新审核要求为应用兼容IPv6
- Glide图片加载库的使用
- KVO底层探索和遇到的常见错误(一)
- 100度小例子
- Entity Framework Tutorial Basics(2):What is Entity Framework?
- Entity Framework Tutorial Basics(1):Introduction
- Spring的applicationContext.xml--spring 配置文件详解
- 旅游小例子
- iOS中保证线程安全的几种方式与性能对比
- 07.07C
- 动画小例子
- 3728 联合权值
- border-radius画企鹅
- 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧