Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone
题目连接:
http://www.codeforces.com/contest/689/problem/A
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
Sample Output
NO
Hint
题意
有一个人把所有人的手机号码都忘了
但是他记得手指的动作,问你他手指的动作是不是唯一的一个号码
题解
暴力模拟一下去按键就好了……
代码
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int x[10]={4,1,1,1,2,2,2,3,3,3};
int y[10]={2,1,2,3,1,2,3,1,2,3};
int mp[10][10];
bool check(int x3,int y3){
for(int i=0;i<s.size();i++)
{
int xx=max(x[s[i]-'0']-x3,0);
int yy=max(y[s[i]-'0']-y3,0);
if(mp[xx][yy]==0)return false;
}
return true;
}
int main(){
scanf("%d",&n);
cin>>s;
int ans = 0;
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)
mp[i][j]=1;
mp[4][2]=1;
for(int j=-4;j<=4;j++)
for(int k=-4;k<=4;k++)
if(check(j,k))
ans++;
if(ans>1)printf("No\n");
else printf("Yes\n");
}
Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题的更多相关文章
- 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 Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- 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 ...
随机推荐
- 九、springboot整合redis二之缓冲配置
1.创建Cache配置类 @Configuration @EnableCaching public class RedisCacheConfig extends CachingConfigurerSu ...
- 09 Command Documentation 命令文档
Command Documentation 命令文档 There is a suite of programs to build and process Go source code. Inste ...
- GitHub安装和使用
GitHub是一个基于git的代码托管平台,付费用户可以建私人仓库,一般的免费用户只能使用公共仓库,也就是代码要公开. Github 由Chris Wanstrath, PJ Hyett 与Tom P ...
- python随笔(二)
range(2,10):不包括10 range(2,10,3):步长为3 range(10,2,-1):从10到2,步长-1.
- java 添加一组元素
在java包中的Arrays和Collection类中都有很多实用方法,可以在一个Collection中添加一组元素,Array.asList()方法接受一个数组或是一个用逗号分隔的元素列表(使用可变 ...
- PowerMock+SpringMVC整合并测试Controller层方法
PowerMock扩展自Mockito,实现了Mockito不支持的模拟形式的单元测试.PowerMock实现了对静态方法.构造函数.私有方法以及final方法的模拟支持,对静态初始化过程的移除等强大 ...
- oplog扩容
Oplog的扩容: 背景:一个由3个节点组成的复制集. 主节点:A 从节点:B,C 需求:Oplog扩容,尽量少的影响业务. 思路:先由从节点开始,一台一台的从复制集中剥离,修改,再回归复制集,最后操 ...
- java8 - 2
import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util. ...
- Android开发——子线程操作UI的几种方法(待续)
方法2 Handler andler mHandler = new Handler() { @Override public void handleMessage(Message msg) { su ...
- 【BZOJ】1566: [NOI2009]管道取珠
题解 假如我们非常熟练的看出来,平方和转有序对统计的套路的话,应该就不难了 我们只需要统计(wayA,wayB)生成的序列一样的有序对个数就行 可以用一个\(n^3\)的dp解决 \(dp[i][j] ...