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


长度为k的回文串个数有9*10^(k-1)
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int num[maxn], a[maxn];
void init()
{
num[] = num[] = ;
for(int i=; i<; i+=)
num[i] = num[i+] = num[i-] * ;
} int main()
{
init();
LL n;
while(cin>> n && n)
{
mem(a, );
int len = ;
while(n - num[len] > )
{
n -= num[len];
len++;
}
n--;
for(int i=len/+; i<=len; i++)
{
a[i] = n%;
n /= ;
}
a[len]++;
for(int i=; i<=len/; i++)
a[i] = a[len-i+];
for(int i=; i<=len; i++)
printf("%d", a[i]);
printf("\n"); }
return ;
}
Palindrome Numbers UVA - 12050(第几个回文数)的更多相关文章
- 009 Palindrome Number 判断一个正整数是否是回文数
详见:https://leetcode.com/problems/palindrome-number/description/ 实现语言:Java 方法一: class Solution { publ ...
- [2014亚马逊amazon] 在线笔试题 大于非负整数N的第一个回文数 Symmetric Number
1.题目 如标题,求大于整数N(N>=0)的第一个回文数的字符串表示形式. 这个题目也是当时笔试第一次见到,花了一个小时才做出了.慢慢总结还是挺简单的. 2.分析 分析如下: (1)一位数N(9 ...
- POJ2402 Palindrome Numbers 回文数
题目链接: http://poj.org/problem?id=2402 题目大意就是让你找到第n个回文数是什么. 第一个思路当然是一个一个地构造回文数直到找到第n个回文数为止(也许大部分人一开始都是 ...
- POJ2402 Palindrome Numbers第K个回文数——找规律
问题 给一个数k,给出第k个回文数 链接 题解 打表找规律,详见https://www.cnblogs.com/lfri/p/10459982.html,差别仅在于这里从1数起. AC代码 #inc ...
- POJ 2402 Palindrome Numbers(LA 2889) 回文数
POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- [Swift]LeetCode479. 最大回文数乘积 | Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...
- leetcode-479-Largest Palindrome Product(找到两个乘数相乘得到的最大的回文数)
题目描述: Find the largest palindrome made from the product of two n-digit numbers. Since the result cou ...
- 有趣的数-回文数(Palindrome number)
文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...
随机推荐
- 'utf-8' codec can't decode byte 0xbc in position 1182: invalid start byte
2.如果是字符集出现错误,建议多选择几种字符集测试一下: 选择的经验是: 如果是爬取到的网页文件,可以查看网页文件的meta标签下的charset属性值.例如: <meta charset=&q ...
- log下一次坑爹的疏忽
今天调试一段十几行的代码,也让我是一顿咒骂...就说说是怎么回事哈哈. 是这样的,这个页面foreach了一个个的div块,每个div里有个a标签,这个按钮绑定了个点击事件.事件走了个ajax,根据返 ...
- Python基础之公共方法
公共方法:就是列表,元组,字典,字符串能共同使用的方法: Python内置函数 内置函数罗列 函数 描述 备注 len(item) 计算容器中的元素个数 del(item) 删除变量 del有两种方法 ...
- test zhenai
web.Document.InvokeScript("eval",new string[]{"document.getElementById('passwordbt'). ...
- 谈谈对Python装饰器的理解
装饰器,又名函数修饰符.笔者觉得函数修饰符,这个名字更能直观的反应他的作用. 函数修饰符语法特征 : @ + 修饰符 函数修饰符的装饰对象: 函数修饰符,就是说他修饰的是 ...
- stm32的PWM占空比
PWM一共有两种模式,PWM1模式:CNT<CRRx为有效电平.CNT>CRRx为无效电平.PWM2模式相反. 有限电平通过设置极性来确定: TIM_OCInitStructure.TIM ...
- CS100.1x Introduction to Big Data with Apache Spark
CS100.1x简介 这门课主要讲数据科学,也就是data science以及怎么用Apache Spark去分析大数据. Course Software Setup 这门课主要介绍如何编写和调试Py ...
- 《Effective Java》学习笔记 —— 枚举、注解与方法
Java的枚举.注解与方法... 第30条 用枚举代替int常量 第31条 用实例域代替序数 可以考虑定义一个final int 代替枚举中的 ordinal() 方法. 第32条 用EnumSet代 ...
- phabricator 结合 arcanist 使用
简介 arcanist 是 phabricator 接口的命令工具,主要用于提交 diff 和 push review 通过的commit. 安装 下载源码,然后指定系统的环境变量即可 $ some_ ...
- GitHub 新手教程 六,Git GUI 新手教程(3),从GitHub远端同步代码库
从GitHub把代码库下载到本地: 1,打开 GitGUI,单击我们之前克隆好的本地库: 2,按图片所示点击,同步远端代码: 3,出现如下提示后,点击“Close”: 4,上面只是把代码下载下来,还没 ...