Codeforces Round #361 (Div. 2) A
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
3
586
NO
2
09
NO
9
123456789
YES
3
911
YES 题意: 给出一个锁屏,问存不存在其他锁屏密码跟改密码有同样的移动模式(例如0->9和8->6 移动方向 距离都一样)
分析:
可以记录每个数字上下左右。然后枚举移动方向和距离,将整个号码拖着移动。看看合不合法。
也可以直接判断该锁屏是否都可以向相同的方向移动(是否都不存在在同一个边界上)如果可以则输出“NO”.
#include <iostream>
#include<cstdio>
using namespace std; int main()
{
int n,x=,y=,z=,l=;
char a[];
scanf("%d",&n);
cin>>a;
for(int i=;i<n;i++)
{
if(a[i]!=''&&a[i]!=''&&a[i]!='')
x++;
if(a[i]!=''&&a[i]!=''&&a[i]!='')
y++;
if(a[i]!=''&&a[i]!=''&&a[i]!=''&&a[i]!='')
z++;
if(a[i]!=''&&a[i]!=''&&a[i]!=''&&a[i]!='')
l++;
} if(x==n||y==n||z==n||l==n)
printf("%s\n","NO");
else
printf("%s\n","YES");
return ;
}
Codeforces Round #361 (Div. 2) A的更多相关文章
- Codeforces Round #361 (Div. 2) C.NP-Hard Problem
题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...
- Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分
D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description Mike a ...
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...
- Codeforces Round #361 (Div. 2) B. Mike and Shortcuts bfs
B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mi ...
- 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) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
- Codeforces Round #361 (Div. 2) D
D - Friends and Subsequences Description Mike and !Mike are old childhood rivals, they are opposite ...
- Codeforces Round #361 (Div. 2) C
C - Mike and Chocolate Thieves Description Bad news came to Mike's village, some thieves stole a bun ...
- Codeforces Round #361 (Div. 2) B
B - Mike and Shortcuts Description Recently, Mike was very busy with studying for exams and contests ...
随机推荐
- xamarin android webview XHR错误
Cross origin requests are only supported for protocol schemes MLHttpRequest cannot load file:///F:/G ...
- Eclipse最常用快捷键
常用快捷键: Ctrl + 1 :快速修复(当编辑器出现红色波浪线时使用此快捷键能快速弹出提示) Ctrl + d :删除当前光标所在的行 Ctrl + z :撤销上一步的操作 Ctrl + y :重 ...
- selenium 下载百度音乐并验证
package baidu; import java.io.File; import java.io.IOException; import java.util.List; import org.ap ...
- PCA 协方差矩阵特征向量的计算
人脸识别中矩阵的维数n>>样本个数m. 计算矩阵A的主成分,根据PCA的原理,就是计算A的协方差矩阵A'A的特征值和特征向量,但是A'A有可能比较大,所以根据A'A的大小,可以计算AA'或 ...
- JTextField 限制指定字符不能输入
txtStartDate.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { int keyChar = e.ge ...
- mysql事务
1. 事务并不专属于mysql 2. 事务的ACID特性 1)原子性(atomicity) 一个事务必须被视为一个不可分割的最小工作单元,整个事务中得所有操作要么全部提交成功,要么全部失败回滚,对于一 ...
- centos 使用 locate
centos 第一次使用locate时报错: locate: can not stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录 因为locate相关的索 ...
- 关于QImage提取单色通道方法(vector)
转载请标明处: 作者:微微苏荷 本文地址:关于QImage提取单色通道方法(vector) 近日,用QT和mxnet结合做一个图像识别的demo.遇到需要把图片从QImage转为vector单色分离的 ...
- ExtJs基础知识总结:自定义弹窗和ComboBox自动联想加载(四)
概述 Extjs弹窗可以分为消息弹窗.对话框,这些弹窗的方式ExtJs自带的Ext.Msg.alert就已经可以满足简单消息提示,但是相对复杂的提示,比如如何将Ext.grid.Panel的控件显示嵌 ...
- react学习与简介
简介: React是Facebook开发的一款JS库 React解决了什么问题? 1).首先是以往mvc模式的缺陷,当代码库庞大时,mvc非常的复杂,每添加新的功能,项目的复杂度就几何倍的增长,导致代 ...