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 ...
随机推荐
- R语言实战读书笔记2—创建数据集(上)
第二章 创建数据集 2.1 数据集的概念 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和变量(variable) ,数据库分析师则称其为记录(record)和字 ...
- HTML浅学入门---基础知识 (1)<基本规则>
HTML: 结构化文档,超文本标记语言 (一)四条基本规则 1.每个开始标记必须和结束标记配套使用.// <tag> </tag> 2.文档中必须包含唯一的打开和关闭标记 ...
- 基于.net mvc的校友录(源程序)
废话不多说,上程序再说: http://pan.baidu.com/s/11MnLo 我.net mvc4的正式学习时长,其实也就一个多月,期间除去玩游戏.听歌.谈恋爱,也就半个月,大神请轻喷~~ 转 ...
- Linux 下的类似Windows下Everything的搜索工具
Windows NTFS有个超级快的搜索工具Everything,非常好用,Linux下有几个类似的命令行工具,太难用了,推荐一个catfish,类似Everything,有GUI,可以自定义一个快捷 ...
- mui开发
http://blog.csdn.net/sunhuaqiang1/article/details/46848005
- [原创] zabbix学习之旅五:如何快速搭建一个报警系统
通过之前的文章,我们已搭建好zabbix server.agent和mail客户端,现在万事俱备,只差在server的界面中进行相应配置,即可快速搭建一个报警系统.总的来说,快速搭建一个报警系统的顺序 ...
- Python 文件读和写
- PHP字符串处理常用方法
strlen("字符串");//取字符串的长度 strcmp($a,$b); //判断两个字符串是否相同,相同返回0,$a>$b返回1,$a<$b返回-1,区分大小写 ...
- c++ ip地址的操作 c版
http://blog.csdn.net/cpp_funs/article/details/6988154 1.htonl ()和ntohl( ) u_long PASCAL FAR ntohl (u ...
- boost之function
boost中function是对函数指针和函数对象的进行封装的模板类. 定义示例:function<int()> func生成一个空的对象,表示函数参数个数为零,返回类型为int. #in ...