Codeforces Round #361 (Div. 2) A. Mike and Cellphone ( 模拟 )
2016-07-12 13:33
323 查看
A. Mike and Cellphone
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201607/21fdff6831219b138ca17b898bec3a98.png)
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":
![](https://oscdn.geek-share.com/Uploads/Images/Content/201607/b6f83bcb7e86dc4409978f9cddab6320.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201607/3e1c0090005d217980a81ad99420f26d.png)
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数字键盘,随后输入一个操作序列,
问该操作序列在键盘上形成的手势是否是唯一的,是YES,否NO。
计算起点与其他点位置之间的差额(方向队列记录),从头开始,直接寻找,模拟过程;
AC代码:
#include <cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
struct node
{
int x;
int y;
};
using namespace std;
int ans[6][5] = {-1,-1,-1,-1,-1,-1 ,1, 2, 3,-1,-1, 4, 5, 6,-1,-1, 7, 8, 9,-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1};
int main()
{
int n;
node q[10];
q[0].x = 4; q[0].y = 2;
q[1].x = 1; q[1].y = 1;
q[2].x = 1; q[2].y = 2;
q[3].x = 1; q[3].y = 3;
q[4].x = 2; q[4].y = 1;
q[5].x = 2; q[5].y = 2;
q[6].x = 2; q[6].y = 3;
q[7].x = 3; q[7].y = 1;
q[8].x = 3; q[8].y = 2;
q[9].x = 3; q[9].y = 3;
while (scanf("%d",&n)!=EOF)
{
node b;
queue<node>dir;
char a[100];
int k;
scanf("%s", a);
for (int i = 0; i < n; i++)
{
int x = a[i] - '0';
if (i == 0) { b = q[x]; k = x; }
else
{
node task;
task.x = q[x].x - b.x;
task.y = q[x].y - b.y;
dir.push(task);
}
}
int count;
for (int i = 0; i <= 10; i++)
{
if (k == i) continue;
queue<node>f = dir;
count = 0;
while (!f.empty())
{
node task = f.front(); f.pop();
int xx = q[i].x + task.x; int yy = q[i].y + task.y;
if (xx >= 1 && xx <= 4 && yy >= 1 && yy<=3 && ans[xx][yy]!=-1 )
{
count++;
}
if (count == n - 1) break;
}
if (count == n - 1) break;
}
if (count == n - 1) printf("NO\n");
else printf("YES\n");
}
return 0;
}
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201607/21fdff6831219b138ca17b898bec3a98.png)
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":
![](https://oscdn.geek-share.com/Uploads/Images/Content/201607/b6f83bcb7e86dc4409978f9cddab6320.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201607/3e1c0090005d217980a81ad99420f26d.png)
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数字键盘,随后输入一个操作序列,
问该操作序列在键盘上形成的手势是否是唯一的,是YES,否NO。
计算起点与其他点位置之间的差额(方向队列记录),从头开始,直接寻找,模拟过程;
AC代码:
#include <cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
struct node
{
int x;
int y;
};
using namespace std;
int ans[6][5] = {-1,-1,-1,-1,-1,-1 ,1, 2, 3,-1,-1, 4, 5, 6,-1,-1, 7, 8, 9,-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1};
int main()
{
int n;
node q[10];
q[0].x = 4; q[0].y = 2;
q[1].x = 1; q[1].y = 1;
q[2].x = 1; q[2].y = 2;
q[3].x = 1; q[3].y = 3;
q[4].x = 2; q[4].y = 1;
q[5].x = 2; q[5].y = 2;
q[6].x = 2; q[6].y = 3;
q[7].x = 3; q[7].y = 1;
q[8].x = 3; q[8].y = 2;
q[9].x = 3; q[9].y = 3;
while (scanf("%d",&n)!=EOF)
{
node b;
queue<node>dir;
char a[100];
int k;
scanf("%s", a);
for (int i = 0; i < n; i++)
{
int x = a[i] - '0';
if (i == 0) { b = q[x]; k = x; }
else
{
node task;
task.x = q[x].x - b.x;
task.y = q[x].y - b.y;
dir.push(task);
}
}
int count;
for (int i = 0; i <= 10; i++)
{
if (k == i) continue;
queue<node>f = dir;
count = 0;
while (!f.empty())
{
node task = f.front(); f.pop();
int xx = q[i].x + task.x; int yy = q[i].y + task.y;
if (xx >= 1 && xx <= 4 && yy >= 1 && yy<=3 && ans[xx][yy]!=-1 )
{
count++;
}
if (count == n - 1) break;
}
if (count == n - 1) break;
}
if (count == n - 1) printf("NO\n");
else printf("YES\n");
}
return 0;
}
相关文章推荐
- CCCC/GPLT L1-010 比较大小
- 使用InspectiveC来查看调用堆栈
- Linux修改文件时候,产生了一个.swap交换文件,如何删除
- 天梯-L2-001. 紧急救援
- deban8 linux 下 virtual box black arch linux 连不了网
- IOS UIScrollview约束问题
- ACM--枚举暴力--HDOJ 1017--A Mathematical Curiosity--水
- Android数据存储
- 116. Populating Next Right Pointers in Each Node && 117. Populating Next Right Pointers in Each Node II
- [置顶] 日常学习记录
- 博客首自戒
- web.xml
- Java Security:Java加密框架(JCA)简要说明
- 快速幂取模——Pupu(HDU 3003)
- 安装GenyMotion模拟器(Mac)
- 'FND: Application Module Pool Enabled'
- Common Subsequence
- iOS控件之UITextView字数控制以及占位符的实现
- JavaScript
- Sunday Algorithm