问题 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. liunx 利用nginx 实现负载均衡

    一般采用软件实现负载均衡的有Nginx.apache.nginx 近年来使用频繁,其官网上面显示可以承载5万并发访问量,太牛了. nginx 相比 apache优势明显:Nginx 服务程序比较稳定, ...

  2. git码云上传本地项目

    可参考:https://blog.csdn.net/huangfei711/article/details/69388230 .在你的项目上鼠标右击点击Git bash git config --gl ...

  3. 【Linux】添加DNS

    1.添加DNS输入命令: vi /etc/resolv.conf 添加一行:nameserver 10.41.132.9 2.查看DNS nslookup 127.0.0.1 | grep Serve ...

  4. Android 基础 一 AndroidManifest.xml

    一.概述 AndroidManifest.xml是Android应用的入口文件,它描述了package中暴露的组件(activities, services, 等等),他们各自的实现类,各种能被处理的 ...

  5. js之DOM对象一

    一.什么是HTML  DOM HTML  Document Object Model(文档对象模型) HTML DOM 定义了访问和操作HTML文档的标准方法 HTML DOM 把 HTML 文档呈现 ...

  6. php可变数量的参数

    PHP 在用户自定义函数中支持可变数量的参数列表.在 PHP 5.6 及以上的版本中,由 ... 语法实现:在 PHP 5.5 及更早版本中,使用函数 func_num_args(),func_get ...

  7. vs问题解决:an operation is not legal in the current state

    debug时弹出提示框:内容有:an operation is not legal in the current state 解决方案: Go to Tools > Options > D ...

  8. Python初探list

    今天要说一个新概念--list,中文可以翻译成列表,是用来处理一组有序项目的数据结构.想象一下你的购物清单.待办工作.手机通讯录等等,它们都可以看作是一个列表.说它是新概念也不算确切,因为我们之前已经 ...

  9. webpack+vue打包之后输出配置文件修改接口文件

    用vue-cli构建的项目通常是采用前后端分离的开发模式,也就是前端与后台完全分离,此时就需要将后台接口地址打包进项目中,but,难道我们只是改个接口地址也要重新打包吗?当然不行了,那就太麻烦了,怎么 ...

  10. net core 使用 rabbitmq

    windows环境安装: https://www.cnblogs.com/ericli-ericli/p/5902270.html .NET Core 使用RabbitMQ https://www.c ...