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

题意:

输出从1开始第i个回文数字,

思路;

只讲思路不贴代码

先将每个位数的回文数字数量存进去,如1位有9个回文,2位数:9, 三位数 :90,四位数:90;

然后由于数字是回文的,所以前一半的数字即可,

因为前一半数字的变化依据的仍然是和上一段结尾的距离 如:12的前一段结尾为9 距离为3,要想变化只能第一位往上加,加三次得:33。

具体推一下便知。

时间: 2024-08-07 21:15:24

UVa - 12050的相关文章

Uva - 12050 Palindrome Numbers【数论】

题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: 1 #include <bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 const int maxn=3010; 5

POJ2402/UVA 12050 Palindrome Numbers 数学思维

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). Additionallynumbers can of course be ordered in size. The ?rst few

UVA 12050 - Palindrome Numbers 模拟

题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; for(sum=i=1;i<=x;i++) sum *= 10; return sum; } int main() { int n, i, j, t, cs[1000], c; while(~scanf("%d", &n)) { if(n==0) break; i=1; while(n>9*

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica