A - Mike and Cellphone
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?
InputThe 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.
OutputIf 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.
ExamplesInput3
586OutputNOInput2
09OutputNOInput9
123456789OutputYESInput3
911OutputYESNoteYou can find the picture clarifying the first sample case in the statement above.
题意:给定一个0-9的数字键盘,随后输入一个操作序列,问该操作序列在键盘上形成的手势是否是唯一的,是则输出YES,否则为NO。
本题可以做一个响亮的边界处理,我们设上下左右方向的向量分别为U、D、L、R,当不可向该方向移动时对应的字母值为1。例如当操作序列含0时,左右下都不可移动,则L=R=D=0;
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int main(){
int n;
char s[];
while(cin>>n>>s){
int U=,D=,L=,R=;
for(int i=;i<n;i++){
if(s[i]=='')
D=R=L=;
if(s[i]==''||s[i]==''||s[i]=='')//上
U=;
if(s[i]==''||s[i]==''||s[i]=='')//左
L=;
if(s[i]==''||s[i]==''||s[i]=='')//右
R=;
if(s[i]==''||s[i]=='')//下
D=;
}
if(U==&&D==&&R==&&L==)//当所有方向都不可走时,即手势唯一
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}
A - Mike and Cellphone的更多相关文章
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- A. Mike and Cellphone(Round 361 Div.2)
写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- Codeforces Round #361 (Div. 2)A. Mike and Cellphone
A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 689A A. Mike and Cellphone(水题)
题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces 361 A - Mike and Cellphone
原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the wa ...
- B - Mike and Cellphone(map)
Problem description While swimming at the beach, Mike has accidentally dropped his cellphone into th ...
- CodeForces 689A -Mike and Cellphone
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142 题目大意: 给定一个0-9数字键盘,随后输入一个操 ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
随机推荐
- Linux 磁盘空间查询&&解决Linux 中“磁盘空间不足”的问题
一.linux 查看目录的剩余空间大小 两个命令df .du结合比较直观 df -h 查看整台服务器的硬盘使用情况 du -lh --max-depth=1 : 查看当前目录下一级子文件和子目录占用的 ...
- 转:scanf的用法
https://blog.csdn.net/u012421456/article/details/18501309 scanf()[通过键盘将数据输入到变量中] 它有两种用法: 用法一: scanf( ...
- kubernetes容器探针检测
系列目录 kubernetes提供了livenessProbe(可用性探针)和readinessProbe(就绪性探针)对容器的健康性进行检测,当然这仅仅简单的关于可用性方面的探测,实际上我们不仅仅要 ...
- Ionic + AngularJS angular-translate 国际化本地化解决方案
欢迎访问我们的网站,网站上有更多关于技术性的交流:http://www.ncloud.hk/技术分享/ionic-plus-angularjs-angular-translate-国际化本地化解决方案 ...
- Bootstrap Table 查询(服务器端)、刷新数据
Refresh from url after use data option <!DOCTYPE html> <html> <head> <title> ...
- poj3040(双向贪心)
Allowance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1540 Accepted: 637 Descript ...
- asyncio协程与并发
并发编程 Python的并发实现有三种方法. 多线程 多进程 协程(生成器) 基本概念 串行:同时只能执行单个任务 并行:同时执行多个任务 在Python中,虽然严格说来多线程与协程都是串行的,但其效 ...
- Andorid——ubuntu下的 NDK / JNI
之前一直有接触源代码里面的JNI体系,知道个大概,仅仅管调进了哪个C/C++的接口,如今记录学习下. 撰写不易,转载请注明出处:http://blog.csdn.net/jscese/article/ ...
- PHP中的面向对象 中的类(class)
2.11 上午讲的是面向对象中的类(class),一个非常抽象的概念, 类里面成员的定义有 public$abc; private$abc(私有变量): protect $abc(受保护的变量): 下 ...
- mysql中索引的使用
索引是加速查询的主要手段,特别对于涉及多个表的查询更是如此.本节中,将介绍索引的作用.特点,以及创建和删除索引的语法. 使用索引优化查询 索引是快速定位数据的技术,首先通过一个示例来了解其含义及作用. ...


