问题 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. ADO.NET连接字符串大全---各种数据库的连接字符串

    ADO.NET连接字符串大全 ADO.NET连接字符串 名称 ADO.NET连接字符串 说明 ADO.NET连接字符串:SQL Server,SQL Server 2005,ACCESS,Oracle ...

  2. JAVA项目中常用的异常处理情况总结

    JAVA项目中常用的异常知识点总结 1. java.lang.nullpointerexception这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用 ...

  3. if __name__ == __'main'__: 判断讲解

    """王思聪作为消费者 要吃热狗生产者 负责做热狗问题:王思聪不清楚对方会生产多少热狗 """from multiprocessing im ...

  4. spring boot 配置文件

    spring boot使用一个全局配置文件:主要是以下两种类型 application.properties  :例:server.port=9998 application.yml(YAML)  : ...

  5. laravel 框架后台主菜单接口

    后台菜单调用接口:/admin/manages ManageRepository类: 每个路由中注册: 等等: 最后后台菜单返回:

  6. laravel 实现一个简单的 RESTful API

    创建一个 Article 资源 php artisan make:resource Article 你可以在 app/Http/Resources 目录下看到你刚刚生成的 Article 资源 当然我 ...

  7. 论文阅读笔记二十八:You Only Look Once: Unified,Real-Time Object Detection(YOLO v1 CVPR2015)

    论文源址:https://arxiv.org/abs/1506.02640 tensorflow代码:https://github.com/nilboy/tensorflow-yolo 摘要 该文提出 ...

  8. java实现满天星swing&awt

    一起有两个类 1.MyStar.java package day02; import java.awt.Color; import javax.swing.JFrame;import javax.sw ...

  9. maven依赖jar导出消失问题

      问题:maven依赖jar导出消失问题 新创新的Maven管理的项目,使用的模板是maven-archetype-quickstart,设置maven管理的jar导出时,如下 在每次”update ...

  10. [转] 那些在使用webpack时踩过的坑

    用webpack的过程,就是一个不断入坑和出坑的过程.回望来时路,一路都是坑啊!现把曾经趟过的那些坑整理出来,各位看官有福了~ 文章末尾有我用到的依赖的版本信息,若你发现某个问题与我在本文中的描述不一 ...