2017ecjtu-summer training #1 UVA 12050

时间:2022-12-20 03:15:41

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的更多相关文章

  1. Uva - 12050 Palindrome Numbers【数论】

    题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...

  2. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  3. POJ2402&sol;UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  4. 2017ecjtu-summer training &num;1 UVA 10399

    It has been said that a watch that is stopped keeps better time than one that loses 1 second per day ...

  5. UVa - 12050

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  6. Palindrome Numbers UVA - 12050(第几个回文数)

    长度为k的回文串个数有9*10^(k-1) #include <iostream> #include <cstdio> #include <sstream> #in ...

  7. 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 ≤ ...

  8. UVa 12050 - Palindrome Numbers &lpar;回文数&rpar;

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...

  9. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

随机推荐

  1. Web前端开发大系概览 (前端开发技术栈)

    前言 互联网建立50多年了,网站开发技术日新月异,但web前端始终离不开浏览器,最终还是HTML+JavaScript+CSS这3个核心,围绕这3个核心而开发出来大量技术框架/解决方案. 我从2000 ...

  2. 在SharePoint中创建可自定义属性的文件夹

    概况 阅读时间:约5分钟 适用版本:SharePoint Server 2010及以上 面向用户:普通用户.管理员.开发人员 难度指数:★★★☆☆ SharePoint中的文件夹分为2种,一种是文档库 ...

  3. Pb (数据存储单位)

    PB (数据存储单位) 编辑 pb指petabyte,它是较高级的存储单位,其上还有EB,ZB,YB等单位. 它等于1,125,899,906,842,624(2的50次方)字节,“大约”是一千个te ...

  4. &lbrack;转&rsqb;JDE910--jas&period;ini参数说明

    配置 jas.ini 文件 jas.ini 文件可以使用 Java™ Application Server (JAS) 来提供 JDE 安装的配置.您必须针对特定于每个环境的 JDE 实例来配置 ja ...

  5. cocos2d-x如何截屏并保存图片

    转自:http://blog.csdn.net/wolfking_2009/article/details/11022693 static void ScreenShoot() { CCSize si ...

  6. saltstack实战4--综合练习1

    规范配置管理 实际工作中可能会有现网环境,基线环境,开发环境. 需要使用saltstack统一管理.机器多了,业务多了,可能配置文件存放的会比较乱,因此可以统一管理起来 我们可以再加2个目录,test ...

  7. java main&lpar;&rpar;静态方法

    java main()方法是静态的.意味着不需要new(),就在内存中存在.而且是属于类的,但是对象还是可以调用的. 若干个包含这个静态属性和方法的对象引用都可以指向这个内存区域.这个内存区域发生改变 ...

  8. Karma-Jasmine之安装与实例详解(一)

    本文先介绍karma-jasmine的安装.接下来的(二)中主要通过实例利用断言库详解karma-jasmine如何进行单元测试. Karma介绍 首先说一下karma,官方是这样给出的,karma不 ...

  9. 形象化理解nice值越高优先级越低

    当我们说起某个人很nice的时候,通常指的是那个人心地善良,很好说话,很容易相处.(相反,aggressive的人很可能是不nice的,因为老想抢夺别人的东西,尤其是在资源有限的情况下,恨不得一个蛋糕 ...

  10. HighCharts之2D柱状图、折线图的组合双轴图

    HighCharts之2D柱状图.折线图的组合双轴图 1.实例源码 DoubleAxis.html: <!DOCTYPE html> <html> <head> & ...