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 ...
随机推荐
- 【转载】分享一些Qt学习资源,欢迎下载
资源来源:http://bbs.csdn.net/topics/390358737 经过我一翻整理,把一些我收集到的Qt学习资源分享给大家,主要适合新手,老鸟可以直接忽略我.要说明一下,很多资源都是在 ...
- iframe的使用
function Report() { var info = document.getElementById("iframeReport"); ...
- c数据结构栈的基本操作(字符逆序输出)
线性栈 输入字符,再输出 #include "stdafx.h" #include<stdlib.h> #include<malloc.h> #define ...
- 关于HTML标签(元素)的那些事?
关于HTML标签(元素)的那些事? 在战场上,知己知彼,方能百战百胜:在商场上,知己知彼,亦能呼风唤雨:在情场上,知己知彼,才能幸福美满.当然啦,在我们前端开发上,亦要知己知彼,才能叱咤风云.关于HT ...
- vector的应用
1.0基本操作 (1)头文件: #include<vector>; (2)创建: vector<int>vec, vector<double>vec, vector ...
- poj3461 字符串匹配 熟悉kmp算法第一题
题意: 计算一个字符串在另一个字符串中出现的次数. #include<cstdio> #include<cstring> #include<algorithm> ...
- WPF 中保存 window(窗口)或者canvas成图片
最近需要用到这个功能,搜了一下不少代码有问题 ,找到一个效果比较好的,支持多级子元素 记一下. private void button_save_window_Click(object sender, ...
- repeater没有数据显示暂无数据,无记录
方法就是在FooterTemplate加个Label并根据repeater.Items.Count判断是否有记录.关键代码如下: <FooterTemplate> <asp:Labe ...
- SpringMVC访问静态资源
SpringMVC访问静态资源 在SpringMVC中常用的就是Controller与View.但是我们常常会需要访问静态资源,如html,js,css,image等. 默认的访问的URL都会被Dis ...
- SQL级联删除——删除主表同时删除从表——同时删除具有主外键关系的表
create table a(id varchar(20) primary key,password varchar(20) not null) create table b(id int iden ...