Uva - 12050 Palindrome Numbers【数论】
题目链接:uva 12050 - Palindrome Numbers
题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1!
下面给出AC代码:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=;
ll num[maxn];
int n,ans[maxn];
void init()
{
num[]=,num[]=num[]=;
for(int i=;i<;i+=)
num[i]=num[i+]=num[i-]*;
}
int main()
{
init();
while(scanf("%d",&n)&&n)
{
int len=;
while(n>num[len])
{
n-=num[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 ;
}
Uva - 12050 Palindrome Numbers【数论】的更多相关文章
- POJ2402/UVA 12050 Palindrome Numbers 数学思维
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
- 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 ≤ ...
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- UVa 10006 - Carmichael Numbers
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...
- Palindrome Numbers(LA2889)第n个回文数是?
J - Palindrome Numbers Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- 2017ecjtu-summer training #1 UVA 12050
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...
- UVa - 12050
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
随机推荐
- Swift 开源项目练习应用
小的View.动画实现练习 拥有着苹果先天生态优势的Swift自发布以来,各种优秀的开源项目便层出不穷.本文作者站在个人的角度,将2014年Swift开源项目做了一个甄别.筛选,从工具.存储.网络.界 ...
- iOS 实现后台 播放音乐声音 AVAudioPlayer 以及铃声设置(循环播放震动)
1.步骤一:在Info.plist中,添加"Required background modes"键,value为:App plays audio 或者: 步骤二: - (BOOL) ...
- 某次送温暖考试的 c题
题目大意: 给定n个点的无根树,树上每个点都有一个非负的点权. 树上的路径的价值定义为树上路径的点权和-树上路径的点权最大值; 现在给定一个参数P询问有多少条路径的价值是P的倍数(注意单点也算路径,路 ...
- Python 接口测试(十)
这里对接口测试9 进行优化升级,前端进行重构后的代码,源码已经开源 经过将近一个月的编写 , TIAPTest 接口测试平台 , 已经部署到服务器,开始运行了. http://60.205.187.1 ...
- 基于Java Mail 进行发送(带附件和压缩附件)的邮件
刚进公司的training, 下面是要求: Self-study of Java Mail library: http://www.oracle.com/technetwork/java/javam ...
- SpringBoot_02_servlet容器配置
二.参考资料 1.Spring boot 自定义端口 2.Spring Boot的Web配置(九):Tomcat配置和Tomcat替换
- pyshark 得到payload
mydata = pkt[okt.highest_layer].data mydata.decode("hex")
- solr 的 field, copyfield ,dynamic field
Field: Field就是一个字段,定义一个Field很简单: <field name="price" type="sfloat" indexed=&q ...
- MySQL数据库学习: 02 —— 数据库的安装与配置
MySQL安装图解 一.MYSQL的安装 1.打开下载的mysql安装文件mysql-5.0.27-win32.zip,双击解压缩,运行“setup. ...
- Linux 使用 cp 命令强制覆盖功能
Q:我们平常在Linux中使用 cp 命令时,会发现将一个目录中文件复制到另一个目录具有相同文件名称时, 即使添加了 -rf 参数强制覆盖复制时,系统仍然会提示让你一个个的手工输入 y 确认复制,令人 ...