CodeForces 689A -Mike and Cellphone
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142
题目大意: 给定一个0-9数字键盘,随后输入一个操作序列,即按键手势,问该操作序列在键盘上形成的手势是否是唯一的,是YES,否NO。手势可往上下左右平移。
解题思路:
由于数字很少,可以把数字的位置表示成坐标,按这个手势的顺序匹配其它的数字(即把这些数字统一上或下或左或右平移),看匹配后的数字还在不在这个键盘上;
#include <cstdio>
#include <iostream>
using namespace std;
int n,coordinate[][]={,,,,,,,,,,,,,,,,,,,};
int dir[][]={-,,,,,-,,};
char str[];
int find(int d)
{
for(int i=;i<n;i++)
{
int x=str[i]-'';
if(x==&&(d==||d==||d==)) return ;
if(coordinate[x][]+dir[d][]<||coordinate[x][]+dir[d][]>||(x!=&&coordinate[x][]+dir[d][]<)||coordinate[x][]+dir[d][]>)
return ;
}
return ;
}
void out()
{
int flag=;
for(int i=;i<;i++)
if(find(i)) {flag=;if(flag) break;}
printf(flag?"NO\n":"YES\n");
}
int main()
{
while(cin>>n)
{
scanf("%s",str);
out();
}
return ;
}
CodeForces 689A -Mike and Cellphone的更多相关文章
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
- codeforces 689A A. Mike and Cellphone(水题)
题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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)A. Mike and Cellphone
A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...
- hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...
- A. Mike and Cellphone(Round 361 Div.2)
写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...
- codeforces 547E Mike and Friends
codeforces 547E Mike and Friends 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define ...
- codeforces 689 Mike and Shortcuts(最短路)
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...
随机推荐
- 前端过滤XSS攻击
日常开发过程中,对于存在用户交互的一些门户网站等,过滤xss攻击是必不可少的. 此处主要记录下我在工作过程中的简单处理方法. 前端过滤XSS攻击, 我这里用的是开源工程 js-xss,官网地址:htt ...
- webservice发送数据,取数据的方式
1.通过调用对方的webservice接口方式,取得对方的数据,并解析(我们取数据) 2.对方调用我们的接口,得到数据.(对方来取) 3.对用对方接口,将我们的数据封装好以后,直接调用对方接口,对方可 ...
- awk中split函数的用法
time='12:34:56' echo $time | awk '{split($0,a,":" ); print a[1]}' 12 echo $time | awk '{sp ...
- RAC配置、安装
RAC 配置及安装 2012年12月30日 星期日 21:49 ******************************************************************* ...
- JavaScript HTML DOM EventListener
JavaScript HTML DOM EventListener addEventListener() 方法 实例 点用户点击按钮时触发监听事件: document.getElementById(& ...
- 64位 CentOS NDK 编译 FFMPEG
64位 CentOS NDK 编译 FFMPEG 一. 参考文章: http://www.cnblogs.com/baopu/p/4733029.html http://www.c ...
- php中的JSON中文处理
最近在PHP中要输出JSON,上网查了一下,对中文支持不太好,要不就先转成utf-8的编码,再用json_encode生成,客户端还要再utf-8转中文.对于网页已经用GB2312的服务器,不想这样折 ...
- windows core audio apis
这个播放流程有一次当初不是很理解,做个记录,代码中的中文部分,原文档是有解释的:To move a stream of rendering data through the endpoint buff ...
- linux防火墙解封某端口
首先,使用netstat –tunlp查看是否23端口被防火墙封掉了: 再使用iptables修改设置, # iptables -I INPUT -p tcp --dport 23 –jACCEPT ...
- hold
嘿嘿,很久没写博客了.一懒一拖一浮躁就不行了. 果然烦心事太多,一直懒得编程.结果还是编程才能平复我啊! 明天那什么,别担心,平常心嘛! 还好,看了几部电影,不算没收获.自己有意思就看看电影,别瞎想啥 ...