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 ...
随机推荐
- 用python+selenium将腾讯首页今日话题的内容自动发表到自己cnblog里
目的:使用pyhton下的unittest单元测试框架并结合selenium的webdriver来实现将腾讯首页的今日话题下的内容自动发表达到自己的cnblog里. 思路:创建QQDailyTopic ...
- sqlite3使用(一)
最近工作接触到sqlite3了,于是用博客记录下,当然只是浅用哈! 参考资料:http://www.runoob.com/sqlite/sqlite-tutorial.html 概念: SQLite ...
- CentOS 基本设置
CentOS 基本设置 1.更改163源 在使用yum的时候,可能yum被锁,可用如下命令解锁:rm -rf /var/run/yum.id 2.编译安装开源软件 安装自己编译的开源软件一般都会在/u ...
- cocos2d-x 3.2 listview scorllview 等容器在小米华为等部分手机显示泛白解决
感觉记不住,代码贴上以免以后难找 在proj.android\src\org\cocos2dx\cpp\AppActivity.java 中的 public class AppActivity ext ...
- JPush极光推送Java服务器端API
// 对android和ios设备发送 JPushClient jpush = new JPushClient(masterSecret, appKey); // 对android和ios设备发送 ...
- 使用curl获取Location:重定向后url
在php获取http头部信息上,php有个自带的函数get_headers(),我以前也是用这个的,听说效率在win上不咋地,再加上最近研究百度url无果,写了cURL获取重定向url的php代码来折 ...
- Nginx-ngx_lua模块原理和内置函数
ngx_lua模块的原理: 1.每个worker(工作进程)创建一个Lua VM,worker内所有协程共享VM:2.将Nginx I/O原语封装后注入 Lua VM,允许Lua代码直接访问:3.每个 ...
- Python error: ascii’/'utf-8′ codec can’t decode byte 0xb8 in position 50: ord
字符串使用了费ascii编码的字符,也就是它代表的16进制的编码超过127. 解决这个问题可以使用下面的方法解决,其实就是设置默认的编码.python 2.x的默认编码是ascii,如果改为utf-8 ...
- 【转】Linux CentOS内核编译:下载CentOS源码、编译2.6.32-220的错误(apic.c:819 error 'numi_watchdog' undeclared)
一.下载CentOS源码 1.1 查看CentOS版本 cat /etc/issue 1.2 查看Linux内核版本 uname -r 1.3 下载 文件名:kernel-2.6.32-220.el6 ...
- 解决TalbleView头部或底部子控件不显示问题
在自定义cell头部控件UITableViewHeaderFooterView(和自定义cell的方法几乎一样)时,出现了头部控件子控件不显示的问题. 注意和自定义cell的区别. .h文件 #imp ...