2017ecjtu-summer training #1 UVA 12050
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally numbers can of course be ordered in size. The first few palindrome numbers are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ...
The number 10 is not a palindrome (even though you could write it as 010) but a zero as leading digit is not allowed.
Input
The input consists of a series of lines with each line containing one integer value i (1 ≤ i ≤ 2 ∗ 109 ). This integer value i indicates the index of the palindrome number that is to be written to the output, where index 1 stands for the first palindrome number (1), index 2 stands for the second palindrome number (2) and so on. The input is terminated by a line containing ‘0’.
Output
For each line of input (except the last one) exactly one line of output containing a single (decimal) integer value is to be produced. For each input value i the i-th palindrome number is to be written to the output.
Sample Input
1
12
24
0
Sample Output
1
33
151
题意 数字回文串从小到大排序,输出第n个回文数字
不会写此题啊,膜一下网上大佬代码,没有全看懂,只看懂一部分,没有注释--_--!,他日再破吧。。。
AC代码
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <stdlib.h>
- #include <iostream>
- #include <sstream>
- #include <queue>
- #include <vector>
- #include <algorithm>
- #define maxn 3000
- using namespace std;
- typedef long long ll;
- ll num[maxn];
- int n, ans[maxn];
- void init()
- {
- num[] = , num[] = num[] = ;
- for (int i = ; i < ; i += )
- num[i] = num[i+] = num[i-] * ; //预处理i位的回文数的个数,9,9,90,90,900....
- }
- int main()
- {
- init();
- while (scanf("%d", &n) && n)
- {
- int len = ;
- while (n > num[len])
- {
- n -= num[len]; //判断第n个回文数字有多少位,len
- len++;
- }
- n--;
- int cnt = len / + ; //写出回文数字后半边
- while (n)
- {
- ans[cnt++] = n % ;
- n /= ;
- }
- for (int i = cnt; i <= len; i++)
- ans[i] = ;
- ans[len]++;
- for (int i = ; i <= len/; i++)
- ans[i] = ans[len-i+]; //前半边由后半边复制过来
- for (int i = ; i <= len; i++)
- printf("%d", ans[i]);
- printf("\n");
- }
- return ;
- }
2017ecjtu-summer training #1 UVA 12050的更多相关文章
- Uva - 12050 Palindrome Numbers【数论】
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...
- UVA 12050 - Palindrome Numbers 模拟
题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...
- POJ2402/UVA 12050 Palindrome Numbers 数学思维
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
- 2017ecjtu-summer training #1 UVA 10399
It has been said that a watch that is stopped keeps better time than one that loses 1 second per day ...
- UVa - 12050
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
- Palindrome Numbers UVA - 12050(第几个回文数)
长度为k的回文串个数有9*10^(k-1) #include <iostream> #include <cstdio> #include <sstream> #in ...
- UVa - 12050 Palindrome Numbers (二分)
Solve the equation: p ∗ e −x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x 2 + u = 0 where 0 ≤ x ≤ ...
- UVa 12050 - Palindrome Numbers (回文数)
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...
- 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)
这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...
随机推荐
- Hosts文件实际应用 配置内部服务器提高访问效率和速度
一 hosts文件的作用和介绍 https://jingyan.baidu.com/article/335530da45485e19cb41c3d6.html https://www.cnblogs. ...
- ListView用法总结C#
ListView是个较为复杂的控件 网上教程写的很乱,C#中文资料太匮乏了,小白叔叔觉得有必要自己出一份了. http://blog.sina.com.cn/s/blog_43eb83b901 ...
- ES6 对象的扩展(上)
属性的简介表示法 允许直接写入变量和函数作为对象的属性和方法,这样的书写更简洁. function f( x, y ) { return { x, y }; } // 等同于 function f( ...
- 在ubuntu上安装pyenv出现的问题
1.安装完pyenv时,并没有出现问题.但在安装python3.6.1时报错: ERROR: The Python ssl extension was not compiled. Missing th ...
- 鸟哥的linux私房菜学习-(五)Linux系统的在线求助man page与info page
1.man page man是manual(操作说明)的简写啦!只要下达:『man date』 马上就会有清楚的说明出现在你面前喔!如下所示: 进入man命令的功能后,你可以按下『空格键』往下翻页,可 ...
- Head First设计模式之模板方法模式
一.定义 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中,使得子类可以不改变算法结构的情况下,重定义该算法中的某些特定步骤. 比较通俗的说法,子类决定如何实现算法中的某些步骤,比如两个一连串 ...
- tensorflow mnist read_data_sets fails
下载处理mnist数据时出现如下错误 VisibleDeprecationWarning: converting an array with ndim > 0 to an index will ...
- 2017-07-20聊聊《C#本质论》
第一次接触<C#本质论>是在这个链接.那时候刚学写C#,而且它的语言风格深深吸引了我,噢对了还有它强大的IDE--VS.这个链接里的书确实不错.文中提到: 虽然这三本书都是外国原著的,但是 ...
- 实体处理模块IEntityModule
在2015年7月16日,XCode新增了实体处理模块IEntityModule,用于拦截实体对象添删改操作. 该接口参考IHttpModule设计理念,横切在实体对象的关键生命周期之中,以达到多实体类 ...
- Windows下安装Selenium
安装python,建议在官网下载python3以上的版本 安装easy_install,找度娘 安装selenium,在命令行窗口下输入:pip install -U selenium 下载chrom ...