codeforces 689A A. Mike and Cellphone(水题)
题目链接:
1 second
256 megabytes
standard input
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?
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.
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.
3
586
NO
2
09
NO
9
123456789
YES
3
911
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 ;
}
codeforces 689A A. Mike and Cellphone(水题)的更多相关文章
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
随机推荐
- 机器学习基础-Logistic回归1
利用Logistic回归进行分类的主要思想是:根据现有数据对分类边界线建立回归公式,以此进行分类. 训练分类器时的做法就是寻找最佳拟合参数,使用的时最优化算法. 优点:计算代价不高,利于理解和实现. ...
- hdu 2063最大匹配
#include<stdio.h> #include<string.h> int link[600],mark[600],map[600][600],m,n; int find ...
- Lucene、Compass学习以及与SSH的整合
一.准备 个人在学习中采用Struts2 + Hibernate3.2 + Spring2.5 + Compass2.2.0, 一下图片为本次学习中用到的jar包: 图中圈出的jar包为本次学习的主要 ...
- @JoinColumn 匹配关联多个字段
两张表结构如下 TABLE_A: ID, COLA1, COLA2 TABLE_B: ID, A_ID, COLB1, COLB2 A和B是一对多的关系. 我在B的BEAN上面,通过Anotation ...
- [NOIP2002] 提高组P1032 字串变换
题目描述 已知有两个字串 A, B 及一组字串变换的规则(至多6个规则): A1 -> B1 A2 -> B2 规则的含义为:在 A$中的子串 A1 可以变换为 B1.A2 可以变换为 B ...
- mysql 常用管理命令
常见的管理mysql命令 (1)用于选择在MySQL工作区指定的数据库(选择数据库): USE Databasename; (2)列出了MySQL数据库管理系统中的所有可访问的数据库: SHOW DA ...
- app后端搜索入门
现在人们的网络生活已经离不开搜索了,遇到不懂的问题,想知道的事情,搜索一下,就知道答案. 在app中,最常见的搜索情景就是搜索用户.只有几百,几千的用户量时,可以直接用用like这样的模糊查询,但是, ...
- Scrambled Polygon--poj2007(极角排序模板)
http://poj.org/problem?id=2007 #include<stdio.h> #include<math.h> #include<algorithm& ...
- Intersecting Lines--POJ1269(判断两条直线的关系 && 求两条直线的交点)
http://poj.org/problem?id=1269 我今天才知道原来标准的浮点输出用%.2f 并不是%.2lf 所以wa了好几次 题目大意: 就给你两个线段 然后求这两个线段所在的 ...
- BZOJ——2563: 阿狸和桃子的游戏
http://www.lydsy.com/JudgeOnline/problem.php?id=2563 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: ...