原题:

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. Scalding初探之番外篇:Mac OS下的安装

    把你从写繁琐的Map-reduce Job中解放出来,写分布式跟写本地程序没两样,Scalding真真代表着先进生产力的方向啊 心动不如行动,赶紧装一个吧 1 安装JDK 2 安装Homebrew r ...

  2. git error

    一,今天在上传代码时出错: $ git push -u origin mastererror: The requested URL returned error: 403 Forbidden whil ...

  3. css模糊效果

    CSS代码: .blur { filter: url(blur.svg#blur); /* FireFox, Chrome, Opera */ -webkit-filter: blur(10px); ...

  4. 2016HUAS_ACM暑假集训2B - The Suspects(感染者)

    并查集初步应用,还不是很熟练.并查集两个主要函数:Union和Find.Union通常把两条不连通的支路使其连通:Find用来查找根节点,必要的要进行路径压缩. 大致题意:0号学生是默认的感染者,在M ...

  5. kuangbin_SegTree A (HDU 1166)

    大牛们的文章里这句 题意:O(-1) 思路:O(-1) 深深地嘲讽了我........ 不过单点更新 区间求和也算是基本操作了吧 (虽然我还是看了好久才理解) 跟之前学图论的时候感觉完全不一样啊orz ...

  6. python百分比数比较大小

    python是无法识别百分比的,估计你的百分比是string,所以需要转成int # !/usr/bin/python3.4 # -*- coding: utf-8 -*- # 百分数转为int de ...

  7. knockout 学习实例5 style

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>&l ...

  8. mysql死锁问题分析

    线上某服务时不时报出如下异常(大约一天二十多次):“Deadlock found when trying to get lock;”. Oh, My God! 是死锁问题.尽管报错不多,对性能目前看来 ...

  9. python模块介绍- SocketServer 网络服务框架

    来源:https://my.oschina.net/u/1433482/blog/190612 摘要: SocketServer简化了网络服务器的编写.它有4个类:TCPServer,UDPServe ...

  10. 企业架构(Enterprise Architecture)

    ylbtech-Miscellaneos: 企业架构(Enterprise Architecture) A,返回顶部 1, 简称EA.是指对企业事业信息管理系统中具有体系的.普遍性的问题而提供的通用解 ...