题目链接:

A. Mike and Cellphone

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

 
Examples
 
input
3
586
output
NO
input
2
09
output
NO
input
9
123456789
output
YES
input
3
911
output
YES

题意;

问按下这些密码的手势顺序是否是唯一的?

思路:

由于数字很少,可以把数字的位置表示成坐标,按这个手势的顺序匹配其它的数字,看匹配后的数字还在不在这个键盘上;

AC代码:
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e5+;
const int maxn=;
const double eps=1e-; int check(int x,int y)
{
if(x>=&&x<=&&y<=&&y>=)return ;
if(x==&&y==)return ;
return ;
}
int fx,fy,ax,ay;
void get_pos(int num)
{
if(num==)fx=,fy=;
else
{
fx=ceil(num*1.0/);
fy=num%;
if(!fy)fy+=;
}
}
void solve(int num)
{
if(num==)ax=,ay=;
else
{
ax=ceil(num*1.0/);
ay=num%;
if(!ay)ay+=;
}
}
int main()
{
int n;
char s[];
read(n);
scanf("%s",s); for(int i=;i<=;i++)
{
if(s[]-''==i)continue;
get_pos(i);//fx/fy;
solve(s[]-'');//ax,ay;
int flag=;
int tx=ax-fx,ty=ay-fy;
for(int j=;j<n;j++)
{
solve(s[j]-'');
if(!check(ax-tx,ay-ty))flag=;
}
if(flag)
{cout<<"NO"<<endl;return ;}
}
cout<<"YES"<<endl;
return ;
}

最新文章

  1. (原)用pixi.js 实现 方块阵点击后原地自转效果
  2. 篇一:JSON格式转换(一)
  3. Linux 命令收集
  4. MySQL中INFORMATION_SCHEMA是什么?(2)
  5. laravel 加中间件的方法 防止直接打开后台
  6. cocos在win平台exe无法使用 UserDefault 解决方法
  7. 【Head-First设计模式】C#版-学习笔记-开篇及文章目录
  8. 通过IP的方式建立PSSession
  9. hibernate 数据库列别名自动映射pojo属性名
  10. MySQL用命令行导出数据库
  11. php版DES
  12. Java安全之对称加密、非对称加密、数字签名
  13. Delphi中的THashTable
  14. 洛谷 P1515 旅行
  15. Visual C++基础知识(win32exe)
  16. 关于adb重启的一些问题
  17. netty&mdash;&mdash;私有协议栈开发案例
  18. java-web中生成文档(一)
  19. 当同时安装Python2和Python3后,如何兼容并切换使用详解(比如pip使用)
  20. xml实体注入学习

热门文章

  1. C#排序1(冒泡排序、直接排序、快速排序)
  2. Codeforces Round #387 (Div. 2) A+B+C+D!
  3. [luoguP1783] 海滩防御(二分 || 最短路 || 最小生成树)
  4. TOYS(poj 2318)
  5. 同步OR异步?WebFlux开发真的比Servlet开发要快?顺便再科普下CompletableFuture
  6. BZOJ1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名
  7. Codeforces Round #296 (Div. 2) D. Clique Problem [ 贪心 ]
  8. windows7 下安装使用memcached(二)
  9. Flex嵌入HTML页面
  10. P1546||2627 最短网络 Agri-Net 洛谷||codevs