CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现。
析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8,如果有数字变成小于等于0了,那么就是不可以,同理,下是+3,8可以变成0,其他的也是这样,
注意左右平移是147,和369,是不能平移,然后就AC了。再简化一下就是如果有123,就不能上移,如果有79就不能下移,如果有147就不能左移,如果有369就不能右移,如果有0就不能下左右移。
代码如下:
#include <iostream>
#include <cstdio> using namespace std;
const int maxn = 9 + 5;
int a[maxn];
int b[maxn];
char s[maxn]; int main(){
int n;
while(scanf("%d", &n) == 1 && n){
scanf("%s", s);
for(int i = 0; i < n; ++i) a[i] = s[i] - '0';
bool ok = false;
for(int i = 0; i < n; ++i)//下
if(a[i] && a[i] != 8) b[i] = a[i] + 3;
else if(a[i] == 8) b[i] = 0;
else b[i] = 10;
int i;
for(i = 0; i < n; ++i) if(b[i] > 9) break;
if(i == n) ok = true;
for(i = 0; i < n; ++i)//上
if(a[i]) b[i] = a[i] - 3;
else b[i] = 8;
for(i = 0; i < n; ++i) if(b[i] <= 0) break;
if(i == n) ok = true;
for(i = 0; i < n; ++i)//右
if(3 == a[i] || 6 == a[i] || 9 == a[i]) b[i] = 10;
else if(a[i]) b[i] = a[i] + 1;
else b[i] = 10;
for(i = 0; i < n; ++i) if(b[i] > 9) break;
if(i == n) ok = true;
for(i = 0; i < n; ++i)//左
if(a[i] == 1 || a[i] == 4 || a[i] == 7) b[i] = -10;
else if(a[i]) b[i] = a[i] - 1;
else b[i] = -10;
for(i = 0; i < n; ++i) if(b[i] <= 0) break;
if(i == n) ok = true;
if(!ok) puts("YES");
else puts("NO");
}
return 0;
}
第二种:
#include <iostream>
#include <cstdio> using namespace std;
const int maxn = 9 + 5;
int a[maxn];
int b[maxn];
char s[maxn]; int main(){
int n;
while(scanf("%d", &n) == 1 && n){
scanf("%s", s);
int l = 0, u = 0, r = 0, d = 0;
for(int i = 0; i < n; ++i){
if(s[i] == '0') l = r = d = 1;
if(s[i] == '1' || s[i] == '4' || s[i] == '7') l = 1;
if(s[i] == '3' || s[i] == '6' || s[i] == '9') r = 1;
if(s[i] == '1' || s[i] == '2' || s[i] == '3') u = 1;
if(s[i] == '7' || s[i] == '9') d = 1;
}
if(u && d && l && r) puts("YES");
else puts("NO");
}
return 0;
}
CoderForces 689A Mike and Cellphone (水题)的更多相关文章
- 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 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- CodeForces 689A -Mike and Cellphone
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142 题目大意: 给定一个0-9数字键盘,随后输入一个操 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
随机推荐
- java web jsp
一.WEB应用的目录结构 通常我们是在IDE中创建web应用程序,IDE自动为我们实现了WEB的目录结构,下面来看如何徒手创建一个WEB程序. 首先来看一下Tomcat自带的一个web应用的目录结构 ...
- java scanner工具类
import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { Scanne ...
- app遍历——appCrawler的使用
1.appCrawler环境配置 1.1 apkinfo获取安装包的报名和mainActivity https://github.com/codeskyblue/apkinfo/releases 使用 ...
- phpcms模块开发中的小问题及解决方法
1.模块菜单中文名出错 在编写安装模块时候可能需要更改extention.inc.php中定义中文名称,由于反复安装或者通过phpcms的扩展->菜单管理 修改菜单名会导致中文名失败.解决办法很 ...
- 使用protocol buffer时关闭警告
在生成的文件头尾添加屏蔽警告的代码. 头部: #pragma warning(push, 2) // --------------------------------------------- 尾部: ...
- nginx正向代理访问百度地图API
正向代理的概念 正向代理,也就是传说中的代理,他的工作原理就像一个跳板,简单的说,我是一个用户,我访问不了某网站,但是我能访问一个代理服务器这个代理服务器呢,他能访问那个我不能访问的网站于是我先连上代 ...
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 是由 ...
- PHP报错open_basedir restriction in effect
问题是出现在了PHP.INI上面了 原因是php.ini里设置了 open_basedir=/var/web/w0895/:/tmp:/usr/lib/php 这里加上相关的目录就可以了 解答:其实o ...
- windows下使用nginx配置tomcat集群
转自:https://blog.csdn.net/csdn15698845876/article/details/80658599
- 【转】TCP、UDP数据包大小的限制
来自:https://blog.csdn.net/caoshangpa/article/details/51530685 1.概述 首先要看TCP/IP协议,涉及到四层:链路层,网络层,传输层,应用层 ...