codeforces 361 A - Mike and Cellphone
原题:
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的更多相关文章
- 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 E - Mike and Geometry Problem
原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him ...
- codeforces 361 B - Mike and Shortcuts
原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going t ...
- codeforces 361 C - Mike and Chocolate Thieves
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Bad ...
- 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 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 361
A题((Mike and Cellphone) 看起来好像需要模拟数字键位的运动,可是,只要判断出那些必然YES的数字组合不就好了么 #include <cstdio> #include ...
随机推荐
- border-image(转载)
本文转自:http://www.zhangxinxu.com/wordpress/2010/01/css3-border-image%E8%AF%A6%E8%A7%A3%E3%80%81%E5%BA% ...
- 第七课 第二节,T语言流程语句(版本5.0)
while语句 循环结构是程序中一种很重要的结构其特点是,在给定条件成立时,反复执行某程序段,直到条件不成立为止给定的条件称为循环条件,反复执行的程序段称为循环体 (注:关键字,while,end) ...
- 读取 RSSI
在 TI 给的 SimpleBleCentral demo 里,读取 RSSI 的原理是:按 CC2540EM 的下键,然后调用 GapCentralRole 里的函数,启动定时器,不断向 OSAL ...
- (转)Deep Learning Research Review Week 1: Generative Adversarial Nets
Adit Deshpande CS Undergrad at UCLA ('19) Blog About Resume Deep Learning Research Review Week 1: Ge ...
- ecstore菜鸟电子面单对接摘要
1.token长度要150以上 2.redirect_uri不一致,保持一致吧先 3.返回的xml解析问题,php5.3里得到的不是数组,而是simplexml,还得再转化一下 4.后期考虑做成通用型 ...
- 初学RabbitMQ
一.RabbitMQ中的一些概念 (1)Connection(连接) 与RabbitMQ建立连接,由ConnectionFactory创建每个Connection至于一个物理server进行连接,此链 ...
- linux gcc头文件搜索路径
#include <>: 直接到系统指定的某些目录中去找某些头文件.#include "": 先到源文件所在文件夹去找,然后再到系统指定的某些目录中去找某些头文件 1. ...
- Linux 下三种方式设置环境变量
1.在Windows 系统下,很多软件安装都需要配置环境变量,比如 安装 jdk ,如果不配置环境变量,在非软件安装的目录下运行javac 命令,将会报告找不到文件,类似的错误. 2.那么什么是环境变 ...
- Python操作mysql之SQLAchemy(ORM框架)
SQLAchemy SQLAchemy 解析: SQLAchemy是python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作, 简言之便是:将对象转换成SQ ...
- UUID生成
>>>Arch Linux # uuidgen From: http://os.51cto.com/art/200709/56613.htm >>>Debian j ...