题目链接: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的更多相关文章

  1. CodeForces 689A Mike and Cellphone (模拟+水题)

    Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...

  2. CoderForces 689A Mike and Cellphone (水题)

    题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...

  3. codeforces 689A A. Mike and Cellphone(水题)

    题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  5. 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 ...

  6. hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)

    hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...

  7. A. Mike and Cellphone(Round 361 Div.2)

    写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...

  8. codeforces 547E Mike and Friends

    codeforces 547E Mike and Friends 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define ...

  9. codeforces 689 Mike and Shortcuts(最短路)

    codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...

随机推荐

  1. java 钱币的单位转换

    将钱转成转换为带指定单位的钱 int money = 10; NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); System ...

  2. C# Chart圖標綁定

    开发软件为VS2010 免去了安装插件之类的麻烦. 最终效果图: 饼状图: 前台设置:设置参数为: :Titles, 添加一个序列,在Text中设置名字. :Series ,添加一个序列,选择Char ...

  3. hdoj1847(博弈论)

    代码: #include<stdio.h>int main(){ int N; while(scanf("%d",&N)!=EOF) printf(N%3==0 ...

  4. Chrome调试(转)

    原文地址:http://blog.csdn.net/chenmoquan/article/details/44943245#comments 觉得写的很适合web开发的新手 Chrome 的开发者工具 ...

  5. 验证视图状态MAC失败解决方案

    验证视图状态 mac 失败.如果此应用程序由网络场或群集承载 请确保 machinekey 配置指定了相同的 validationkey 和验证算法.不能在群集中使用 autogenerate. 总是 ...

  6. 汇总前端最最常用的JS代码片段

    html5选择器 //参数均接收一个合法的css选择器 element = document.querySelector('.foo,.bar');//返回带有foo或者bar样式类的首个元素 ele ...

  7. js获取当前时间戳与日期比较

    如何用javascript获取当前时间戳: 复制代码 代码示例: 方法1: var timestamp = date.parse(new date()); 结果:1280977330000 方法2: ...

  8. 使用Raphael 画图(二) 扩展的图形 (javascript)

    看这文章前,建议先看第一编文章<使用Raphael 画图(一) 基本图形 (javascript)>. 在Raphael基础上扩展的图形: 要运行该例子要引入附件的2个js包.(g.rap ...

  9. 一个关于导出excel模板的实例

    1 首先jsp页面 点击模板下载,会自动下载模板excel,效果如下 让我们看源码: 1 jsp页面 <div class="tab-pane" id="profi ...

  10. 在iOS7中修改状态栏字体的颜色-b

    状态栏的字体为黑色: UIStatusBarStyleDefault 状态栏的字体为白色: UIStatusBarStyleLightContent 一.在 info.plist  中,将 View ...