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 ...
随机推荐
- POJ-1067取石子游戏,威佐夫博弈范例题/NYOJ-161,主要在于这个黄金公式~~
取石子游戏 Time Limit: 1000MS Memory Limit: 10000K Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取 ...
- Linux CentOS命令行界面字体重复问题解决记录
问题描述: 安装完CentOS 6.5 mini版之后,安装图形界面,启动之后出现如下问题,字体有重复 应该是因为字体原因, 我的解决方法: yum -y install dejavu-sans-* ...
- 【python可视化系列】python数据可视化利器--pyecharts
学可视化就跟学弹吉他一样,刚开始你会觉得自己弹出来的是噪音,也就有了在使用python可视化的时候,总说,我擦,为啥别人画的图那么溜: [python可视化系列]python数据可视化利器--pyec ...
- POJ 1635 树的最小表示法
题目大意: 用一堆01字符串表示在树上走动的路径,0表示往前走,1表示往回走,问两种路径方式下形成的树是不是相同的树 我们可以利用递归的方法用hash字符串表示每一棵子树,然后将所有子树按照字典序排序 ...
- isNaN+parseFloat进行统计以及对NaN的处理【JS验证数字】
今天遇到这么一个需求: 对数据进行统计,可是在统计的时候parseFloat的时候出来一个NaN.后来用isNaN判断,如果是NaN,就给其设置一个初值. 先看对两个方法的解释 parseFloat: ...
- 把excel导入到mysql中
方法很多,不过建议你先看看mysql的开发文档,里面写的很详细的,如果你懒得看,可以看下面的 1.有个软件PHP Excel Parser Pro v4.2可以 2.可将Excel存成csv格式.然后 ...
- [Bzoj1030][JSOI2007]文本生成器(AC自动机)(dp)
1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 5254 Solved: 2172[Submit][Stat ...
- Java面试题总结(一)---Java基础
Java面试题总结(一)---Java基础 1.面向对象的特征有哪些? 答:面向对象的特征主要有以下几个: 1)抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方 ...
- Maven创建项目时出现Generating project in Interactive mode就一直卡住的解决方案
使用maven命令在创建项目的时候出现 Generating project in Interactive mode 然后就一直卡住 网上搜做了很多解决方案 有说各种方案的,最后找到了一种.实验成功 ...
- SAS学习笔记 - R的数据操作
1.对象 1.1 对象及其内在属性 R中的处理数据就是对象,每个对象可以包含多个元素.对象有两个内在属性:类型和长度.类型是对象元素的基本种类,共四种:数值型,字符型,复数型和逻辑型.对象的类型和长度 ...