CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone
题目链接:
http://acm.hust.edu.cn/vjudge/contest/121333#problem/E
Description
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.
Sample Input
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
题意:
判断是否有路径形状一致的按键序列;
题解:
正确建坐标系来量化各按键间的转移过程,暴力求解;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<list>
#define LL long long
#define maxn 210000
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
using namespace std;
int n;
struct node{
int x,y;
};
node pos[] = {{2,4},{1,1},{2,1},{3,1},{1,2},{2,2},{3,2},{1,3},{2,3},{3,3}};
int path[15];
bool is_ok(int x,int y) {
if(x==1&&y==4 || x==3&&y==4) return 0;
return x>=1&&x<=3&&y>=1&&y<=4;
}
int main(int argc, char const *argv[])
{
//IN;
while(scanf("%d",&n) != EOF)
{
getchar();
for(int i=1; i<=n; i++){
int c = getchar();
path[i] = c-'0';
}
int flag = 1;
for(int i=0; i<=9; i++){
if(i == path[1]) continue;
flag = 1;
int curx = pos[i].x;
int cury = pos[i].y;
for(int j=2; j<=n; j++){
int dx = pos[path[j]].x - pos[path[j-1]].x;
int dy = pos[path[j]].y - pos[path[j-1]].y;
curx += dx; cury += dy;
if(!is_ok(curx,cury)) {flag=0;break;}
}
if(flag) {puts("NO");break;}
}
if(!flag) puts("YES");
}
return 0;
}
CodeForces 689A Mike and Cellphone (模拟+水题)的更多相关文章
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- CodeForces 689A -Mike and Cellphone
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142 题目大意: 给定一个0-9数字键盘,随后输入一个操 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
随机推荐
- 预定义的类型“Microsoft.CSharp.RuntimeBinder.Binder”未定义或未导入
http://www.mzwu.com/article.asp?id=3611 因为新加了Microsoft.CSharp的引用, 只需要重新生成一下项目,就可以消除这个错误提示
- eclipse运行emulator时,PANIC:Could not open emulator的解决办法
使用eclipse启动emulator的时候,出现PANIC:Could not open emulator,模拟器无法正常的运行. 经过搜索得知,因为我的SDK的环境变量出问题,需要重新配置下环境变 ...
- Lunix中文乱码解决方案
sudo vi /var/lib/locales/supported.d/local#添加下面的中文字符集zh_CN.GBK GBKzh_CN.GB2312 GB2312zh_CN.GB18030 G ...
- CY7C68013A的一点总结
一. 值得参考的资料:FX2 TechRefManual.USB应用开发宝典. LabVIEW-USB通信简单教程(用于参考生成labview驱动程序).USB设备请求和描述符整理(仅用于理解描述符的 ...
- sublime安装插件
今天因为某些原因,把 sublime 卸载掉了,然后来安装的时候,发现 Package Control 无法安装了,或者安装好后运行 ctrl + shift + p,会报 错误,截图如下: 然后就 ...
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
- bzoj2800
这题好难,翻了一下波兰文的题解……这好像是当年唯一没人A的题目 首先区间修改不难想到差分,我们令d1=x1,dn+1=-xn,di=xi-xi-1 注意Σdi=0,这样对于[l,r]的修改(比如+a) ...
- UVa 548 Tree【二叉树的递归遍历】
题意:给出一颗点带权的二叉树的中序和后序遍历,找一个叶子使得它到根的路径上的权和最小. 学习的紫书:先将这一棵二叉树建立出来,然后搜索一次找出这样的叶子结点 虽然紫书的思路很清晰= =可是理解起来好困 ...
- sql2005主从数据库同步配置
网站规模到了一定程度之后,该分的也分了,该优化的也做了优化,但是还是不能满足业务上对性能的要求:这时候我们可以考虑使用主从库.主从库是两台服务器上的两个数据库,主库以最快的速度做增删改操作+最新数据的 ...
- 【iOS-cocos2d-X 游戏开发之九】Cocos2dx利用CCSAXParser解析xml数据&CCMutableDictionary使用与注意!
本站文章均为李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/iphone-cocos2dx/694.html ☞ ...