Good Morning
题目链接:Good Morning
题目大意:按键盘上的数字,只能在此位置的基础上往右往下按,要求输出与所给值差的绝对值最小的数
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int maxn=1e9+;
int a[][];
bool vis[];
int f[];
int k; bool judge(int x)
{
int tot=;
int s[];
for( ;x;x/= )
{
s[++tot]=x%;
}
for(int i=tot; i>; i-- )//判断每一位是否符合题目所给的输出条件
{
if( !a[s[i]][s[i-]] ) return false;
}
return true;
} void init()
{
//打表1.a[i][j]表示从i键可以到j键打表为1,其他从i不可到的键为0
a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=;
a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=;
a[][]=; a[][]=; a[][]=;
a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=; a[][]=;
a[][]=; a[][]=; a[][]=; a[][]=; a[][]=;
a[][]=; a[][]=;
a[][]=; a[][]=; a[][]=; a[][]=;
a[][]=; a[][]=; a[][]=;
a[][]=;
a[][]=; memset(vis,false,sizeof(vis));
memset(f,-,sizeof(f));
//打表2,标记0到210之间所有符合输出条件的数
for(int i=;i<=; i++ )
{
if( judge(i) ) vis[i]=true;
}
//打表3,暴力试i的符合输出的数,试i-1,i-2,i-3,,,2,1,0; i; i+1,i+2,i+3,....i+210
for(int i=; i<=; i++ )
{
for(int j=; j<=; j++ )
{
if( i-j>= && vis[i-j] )
{
f[i]=i-j;
break;
}
if( i+j<= && vis[i+j] )
{
f[i]=i+j;
break;
}
}
}
} int main()
{
int t;
scanf("%d",&t);
init();
while( t-- )
{
scanf("%d",&k);
printf("%d\n",f[k]);
}
return ;
}
随机推荐
- 【解决方案】文件上具有 Web 标记,请删除 Web 标记
错误: 无法处理文件 Form1.resx,因为它位于 Internet 或受限区域中,或者文件上具有 Web 标记.要想处理这些文件,请删除 Web 标记. 解决方法: 文件-右键-属性 点击”解 ...
- python中字符串的常用(部分)处理方法
myStr = "hello world itcast and hahaitcastcpp" 方法的查询方法: help(myStr.replace) myStr.find(&qu ...
- Java之路---Day02
2019-10-17-20:21:22 顺序结构: 概述:顺序执行,根据编写的顺序,从上到下执行语句 判断语句1-if: if语句第一种格式: if(关系表达式){ 语句体; } 执行流程: 1.首先 ...
- python的常见内置模块之-----time
1.time模块 a.时间戳:print(time.time()) 从1970年到现在的时间,秒数 import time print(time.time()) >>>157448 ...
- Replication Controller 和 Replica Set
使用Replication Controller . Replica Set管理Pod Replication Controller (RC) 简写为RC,可以使用rc作为kubectl工具的快速管理 ...
- Python的插件化开发概述
Python的插件化开发概述 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.插件化开发 动态导入: 运行时,根据用户需求(提供字符串),找到模块的资源动态加载起来. 1> ...
- Linux必知必会--grep
花更少的时间,去验证一件事情:你到底是富翁,还是贫民. --一位历经沧桑的炒客 转自:https://man.linuxde.net/grep grep命令 grep(global search re ...
- C#锁对象代码
private static readonly object SequenceLock = new object(); private static readonly object SequenceL ...
- LeetCode LCP 3 机器人大冒险
题目解析: 对于本题主要的核心是对于一个指令字符串如“RURUU”,如果我们假设它的终点坐标为(8,8),其实只要统计指令字符串中的R的个数和U的个数(对于我给出的例子而言,num_R == 2,nu ...
- Jenkins+robotframework单机版简约教程
迫于某人极渴望学自动化测试,因此写下此简约教程.妈蛋我是个JAVA后端开发啊... 此教程为基于window系统的Jenkins单机版,测试代码无版本控制的精要压缩版本教程,勿喷 前提:通过Jenki ...