原题:

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

原题

提示:当当前手势可以左移一个或者右、上、下 ,即代表不唯一,输出NO。暴力判断就好,比如包含1,4,7,0 之一的number就是不可以左移的。如果四个方向都不可移动就是YES。

代码:

#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define MAX(x,y) (((x)>(y)) ? (x) : (y))
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define ABS(x) ((x)>0?(x):-(x)) const int inf = 0x7fffffff;
const int N=;
char a[N];
int b[N]; int n; bool can_move_left()
{
for(int i=;i<n; i++){
if(b[i]== ||b[i]== ||b[i]== ||b[i]==)
return false;
}
return true;
} bool can_move_right()
{
for(int i=;i<n; i++){
if(b[i]== ||b[i]== ||b[i]== ||b[i]==)
return false;
}
return true;
} bool can_move_up()
{
for(int i=;i<n; i++){
if(b[i]== ||b[i]== ||b[i]==)
return false;
}
return true;
} bool can_move_down()
{
for(int i=;i<n; i++){
if(b[i]== ||b[i]== ||b[i]==)
return false;
}
return true;
} int main()
{ cin>>n;
scanf("%s",a);
for(int i=; i<n; i++){
b[i]=a[i]-''+;
} int ok=;
if(ok == ){
if(can_move_left()) ok=;
}
if(ok == ){
if(can_move_right()) ok=;
}
if(ok == ){
if(can_move_up()) ok=;
}
if(ok == ){
if(can_move_down()) ok=;
} printf("%s\n",ok? "NO":"YES"); return ;
}

codeforces 361 A - Mike and Cellphone的更多相关文章

  1. codeforces 689A A. Mike and Cellphone(水题)

    题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. codeforces 361 E - Mike and Geometry Problem

    原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him ...

  3. codeforces 361 B - Mike and Shortcuts

    原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going t ...

  4. codeforces 361 C - Mike and Chocolate Thieves

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad ...

  5. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  6. 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 ...

  7. CodeForces 689A Mike and Cellphone (模拟+水题)

    Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...

  8. A. Mike and Cellphone(Round 361 Div.2)

    写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...

  9. 套题 codeforces 361

    A题((Mike and Cellphone) 看起来好像需要模拟数字键位的运动,可是,只要判断出那些必然YES的数字组合不就好了么 #include <cstdio> #include ...

随机推荐

  1. pasa的安装

    介绍: http://pasapipeline.github.io/ 参考别人的安装教程:http://sihua.us/pasa.htm 软件下载: https://github.com/PASAp ...

  2. R正则表达式的问题

    今天在处理R的正则表达式的时候发现,R的正则式中的转义字符和linux.python等的还不一样. Linux是使用"\",而R中则使用"[]"! # 我想要将 ...

  3. Sprint第二个冲刺(第九天)

    一.Sprint 计划会议: 现在简单说一下Sprint2的进展情况:大部分功能已经完成或者正在做,此次Sprint2中最难的设计商家的数据库表格已经完成了,剩下的其他功能都是比较耗时的,现在也在抓紧 ...

  4. Python 爬虫学习 urllib2

    用urllib2抓取被限制的网站页面 # coding:utf-8 import urllib2 url = "http://blog.csdn.net/troubleshooter&quo ...

  5. Android 扫一扫----ZXing 的使用

    1. 首先现在ZXing的lib 2. 在Android Studio集成ZXing. public void scan(View view){ startActivityForResult(new ...

  6. Java事务处理全解析(五)—— Template模式

    在本系列的上一篇文章中,我们讲到了使用TransactionManger和ConnectionHolder完成线程安全的事务管理,在本篇中,我们将在此基础上引入Template模式进行事务管理. Te ...

  7. Oracle导入和导出

    导出:EXP userid=<username>/<password>@<service_name> file=<dmpname> e.g.exp sa ...

  8. Hadoop的管理目录

    HDFS文件结构 1.NameNode的文件结构,NameNode会创建VERSION.edits.fsimage.fstime文件目录.其中dfs.name.dir属性是一个目录列表,是每个目录的镜 ...

  9. java maven诡异的错误no class found

    从服务器下载一个java web项目,启动老提示no class found,查看maven依赖库,相关的jar包都已经引入.同样一个项目,在别的机器都可以运行,唯独在我本机运行出错. 为了排错,将其 ...

  10. Array,ArrayList、List<T>、HashSet<T>、LinkedList<T>与Dictionary<K,V>

    Array: 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. 但是数组存在一些不足的地方.在数组的两个数据间插入数据是很麻烦的,而且在声明数组的时候 ...