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 ...
随机推荐
- iOS常见的几种加密方法(base64.MD5.Token传值.系统指纹验证。。加密)
普通加密方法是讲密码进行加密后保存到用户偏好设置中 钥匙串是以明文形式保存,但是不知道存放的具体位置 一. base64加密 base64 编码是现代密码学的基础 基本原理: 原本是 8个bit 一组 ...
- Kendo UI使用笔记
1.Grid中的列字段绑定模板字段方法参数传值字符串加双引号: 上图就是个典型的例子,openSendWin方法里Id,EmergencyTitle,EmergencyDetail 三个参数,后两个参 ...
- bzoj 3991: [SDOI2015]寻宝游戏
Description 小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩家可以任意选择一个村庄,瞬间转移到这个村庄,然后可 ...
- [E::hts_idx_push] NO_COOR reads not in a single block at the end 10 -1
在分析转录组数据时,用bowtie2比对生成的bam文件,下一步call peak使用m6Aviewer,需要bam文件的index文件.所以我直接敲命令 samtools index xx.bam ...
- KandQ:单例模式的七种写法及其相关问题解析
设计模式中的单例模式可以有7种写法,这7种写法有各自的优点和缺点: 代码示例(java)及其分析如下: 一.懒汉式 public class Singleton { private static Si ...
- C#语言和SQL Server第八章笔记
一: ...
- Ruby学习之元编程
Kernel#evel()方法 和Object#instance_evel().Module#class_evel()方法类似,evel()方法也是一个内核方法,Object#instance_eve ...
- leetcode — linked-list-cycle
/** * Source : https://oj.leetcode.com/problems/linked-list-cycle/ * * Given a linked list, determin ...
- 由浅入深理解Java线程池及线程池的如何使用
前言 多线程的异步执行方式,虽然能够最大限度发挥多核计算机的计算能力,但是如果不加控制,反而会对系统造成负担.线程本身也要占用内存空间,大量的线程会占用内存资源并且可能会导致Out of Memory ...
- Xposed hook布局类资源文件的获取
如题,可以hook状态栏,为系统状态栏添加一个TextView @Override public void handleInitPackageResources(XC_InitPackageResou ...