问题 J: Palindromic Password

时间限制: 3 Sec  内存限制: 128 MB
提交: 217  解决: 62
[提交][状态][讨论版][命题人:admin]

题目描述

The IT department at your school decided to change their password policy. Each password will have to consist of N 6-digit numbers separated by dashes, where N will be determined by the phase of the moon and the weather forecast for the day after it will be generated.
You realized that, if all of the numbers were palindromes (same numbers as the original ones if read backwards), you would have to remember a bunch of 3-digit numbers, which did not sound that bad (at the time).
In order to generate your password of N numbers, you get a list of N randomly generated 6-digit numbers and find the palindromic number closest to them.
Of course, you would like to automate this process...

输入

The first line of the input contains a single positive integer N≤1000 indicating the number of six-digit numbers in the input. Each of the next N lines contains a six-digit number without leading zeroes.

输出

For each six-digit number in the input, output another six-digit number that is closest to it and is also a palindrome. “Closest” in this context means “a number having the smallest absolute difference with the original number”. If there are two different numbers satisfying the above condition, output the smaller one
of the two. Remember, no leading zeroes.

样例输入

2
123321
123322

样例输出

123321
123321 求出这个数的最接近的回文数 嗯 尽管这个时间很大 但是还是不能直接暴力的 判断回文数的时候其实它前后不一样有一个不一样我们就可以跳过了,并且范围从1e6枚举到1e7太呆了,而且肯定要超时的。
既然是最接近的回文数,那么在给出这个数的上下一个范围内一定可以找到,我们可以限制出这个范围(随意)。
 #include<bits/stdc++.h>
using namespace std; const int limit = ;
int main()
{
int n;
scanf("%d",&n);
for(int i=; i<n; i++)
{
int num;
scanf("%d",&num);
int ans;
int dis = ;
int r = num+limit;
int l = num>=?num-limit:limit;
for(int j=l; j<=r; j++)
{
int a = j%;
int f = j/;
if(a == f)
{
int b = j/%;
int e = j/%;
if(b == e)
{
int c = j/ % ;
int d = j/%;
if(c == d && abs(num-j) < dis)
{
dis = abs(num - j);
ans = j;
}
}
}
}
printf("%d\n",ans);
}
}

问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)的更多相关文章

  1. 问题 C: Frosh Week(2018组队训练赛第十五场)(签到)

    问题 C: Frosh Week 时间限制: 4 Sec  内存限制: 128 MB提交: 145  解决: 63[提交][状态][讨论版][命题人:admin] 题目描述 Professor Zac ...

  2. 备战省赛组队训练赛第十八场(UPC)

    传送门 题解:by 青岛大学 A:https://blog.csdn.net/birdmanqin/article/details/89789424 B:https://blog.csdn.net/b ...

  3. 备战省赛组队训练赛第十六场(UPC)

    传送门 题解: by 烟台大学 (提取码:8972)

  4. 备战省赛组队训练赛第十四场(UPC)

    codeforces:传送门 upc:传送门 外来题解: [1]:https://blog.csdn.net/ccsu_cat/article/details/86707446 [2]:https:/ ...

  5. UPC Contest RankList – 2019年第二阶段我要变强个人训练赛第十五场

    传送门 A: Colorful Subsequence •题意 给一个长为n的小写字母序列,从中选出字母组成子序列 问最多能组成多少种每个字母都不相同的子序列 (不同位置的相同字母也算是不同的一种) ...

  6. UPC个人训练赛第十五场(AtCoder Grand Contest 031)

    传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...

  7. 2018牛客网暑假ACM多校训练赛(第五场)H subseq 树状数组

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-H.html 题目传送门 - https://www.no ...

  8. 2018牛客网暑假ACM多校训练赛(第五场)F take 树状数组,期望

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-F.html 题目传送门 - https://www.no ...

  9. UPC Contest RankList – 2019年第二阶段我要变强个人训练赛第十四场

    A.JOIOJI •传送门 [1]:BZOJ [2]:洛谷 •思路 在一个区间(L,R]内,JOI的个数是相等的,也就是R[J]-L[J]=R[O]-L[O]=R[I]-L[I], 利用前缀和的思想, ...

随机推荐

  1. JS打开新的窗口

    一.使用JS打开新窗口 1. 超链接<a href="http://www.wumz.me" title="Mauger`s Blog">Welco ...

  2. Oracle11g 体系结构

    一:Oracle11g 体系结构 二:逻辑储存结构 二.1:数据块(data blocks) ----通过 v$parameter数据字典来查询oracle标准数据块的大小. SYS@orcl> ...

  3. ES6学习路上的小学生,promise处理异步操作,简易原始起步之用。先能用,再深究!

    ES6的promise对象,让我们更容易的处理这样的需求:执行完一个方法以后,再去执行下一个方法. 理解尚浅之时,先用于项目之中. var promise1 = new Promise(functio ...

  4. plugin-barcodescanner 报错

    https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/418 ionic cordova platform rm andr ...

  5. LeetCode(107): 二叉树的层次遍历 II

    Easy! 题目描述: 给定一个二叉树,返回其节点值自底向上的层次遍历. (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 例如:给定二叉树 [3,9,20,null,null,15,7], ...

  6. 【linux】Linux误删C基本运行库libc.so.6急救方法

    转自:http://www.cnblogs.com/fjping0606/p/4551475.html 下面全文都是拷贝的上面链接的内容. 首先普及一下关于libc.so.6的基本常识: libc.s ...

  7. Client-Side Attacks

    1.之前看到中间人攻击方式,要使用ssl服务构架一个劫持会话,使得攻击者和被攻击者客户端连接.ssl 服务(secure Socket Layer安全套接) ,以及后续出现的TSL(Transport ...

  8. Pycharm同步本地代码至GitHub

    注册github账号 github地址,进入注册账号 安装git Windows下载地址1 Windows下载地址2 在官方下载完后,双击exe文件进行安装,安装到Windows Explorer i ...

  9. binlog2sql之MySQL数据闪回实践

    DBA或开发人员,有时会误删或者误更新数据,如果是线上环境并且影响较大,就需要能快速回滚.传统恢复方法是利用备份重搭实例,再应用去除错误sql后的binlog来恢复数据.此法费时费力,甚至需要停机维护 ...

  10. Java接口自动化测试之Maven项目的创建(一)

    这里使用Idea创建Maven项目, 过程非常简单, 装好JDK和Idea 1. 安装完后,打开Idea, 选择File→New→Project, 如图 2. 选择maven, 点击Next, 如图 ...