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). 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
题意:给出i,输出第i个回文数,不能有前导0.
题解:第一和最后一位不为0,
我们预处理i位数有多少,以及 在不是第一位和最后一位情况下i位有多少情况
再不断细分就好了
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; ll a[N],sum[N],b[N],s;
void init() {s=;
a[] = ;b[] = ;
a[] = ;b[] = ;
for(int i=;i<=;i++) {
a[i] = a[i-] * ;
}s=;
for(int i=;i<=;i++) {
b[i] = *a[i-];
s+=b[i];
// cout<<s<<endl;
}
}
int main() {
init();
ll n, num, ans[N];
while(scanf("%lld",&n)!=EOF) {
if(!n) break;
mem(ans);
int l,r,mm;
for(int i=;i<=;i++) {
if(b[i]>=n) {
num = i;
mm = num;
l = , r = num;
while(l<=r) {
if(num == ) {
if(l!=) n--;
ans[l] = n;
ans[r] = n;break;
}
if(num == ) {
if(l!=)n--;
ans[l] = n;
ans[r] = n;break;
}
ans[l] = n/a[num-] + (l == ?:);
n = n%a[num-];
if(n == && num-!=) {
ans[l]--;
n = a[num-];
}
ans[r] = ans[l];
l++,r--;num-=;
}
break;
}
n -= b[i];
}
for(int i=;i<=mm;i++) printf("%lld",ans[i]);
printf("\n");
}
return ;
}
代码
POJ2402/UVA 12050 Palindrome Numbers 数学思维的更多相关文章
- Uva - 12050 Palindrome Numbers【数论】
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...
- UVa 12050 - Palindrome Numbers (回文数)
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...
- UVA 12050 - Palindrome Numbers 模拟
题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...
- 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 ≤ ...
- HDU 6659 Acesrc and Good Numbers (数学 思维)
2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...
- UVA 11461 - Square Numbers 数学水题
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- UVa 10006 - Carmichael Numbers
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...
- HDU 5062 Beautiful Palindrome Number(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...
随机推荐
- hdu 5101 Select
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5101 Select Description One day, Dudu, the most cleve ...
- hdu 1702 ACboy needs your help again!
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Description ACboy w ...
- android开发中系统自带语音模块的使用
android开发中系统自带语音模块的使用需求:项目中需要添加语音搜索模块,增加用户体验解决过程:在网上搜到语音搜索例子,参考网上代码,加入到了自己的项目,完成产品要求.这个问题很好解决,网上能找到很 ...
- Timer Design in StatusBar
Timer in StatusBar we need to show local time in StatusBar. solution: 1. add textblock control 2. bi ...
- 45.modelsim仿真include文件
modelsim仿真include文件会出现找不到文件的情况,这是因为include文件路径有两种,一种是相对路径,另一种是绝对路径. 相对路径: 如果 ‘include "primitiv ...
- 触摸屏校准tslib的配置文件
./autogen.sh#sleep 10./configure --prefix=/usr/lxl/tslib --host=arm-linux CC=arm-linux-gcc#sleep 100 ...
- EasyUI datagrid frozencolumn的bug???
今天碰到了个很蛋疼的问题.我用到了easyui 的 treegrid,内容只显示一列,我把它设置成了冻结列. 在谷歌调试下,因为内容比较多,所以,会有竖向的滚动条.但是,到了ie和火狐,滚动条神奇般没 ...
- 说明&总目录
1. 说明 1.1 这是一个乱七八糟的博客,包含遇到的各类问题,甚至会有奇♂怪的东西~ 1.2 作者目前本科生,懒虫一只,喜欢吃喝玩乐看动漫,更喜欢睡觉 1.3 文章难免有错,欢迎指出 1.4 语死早 ...
- Delphi 调试日子 - 莫名其妙的堆溢出
这个是个很有意思的事情,这一个成熟的模板上更改,同样的属性,同样的方法,新的组件在载入过程中就是报错. “Stack overflow” 因为有初始化过程,担心是不是那个地方有问题,由于是在属性赋值过 ...
- python中fork()函数生成子进程分析
python的os module中有fork()函数用于生成子进程,生成的子进程是父进程的镜像,但是它们有各自的地址空间,子进程复制一份父进程内存给自己,两个进程之 间的执行是相互独立的,其执行顺序可 ...