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 ...
随机推荐
- java中线程的几种状态和停止线程的方法
1.线程的状态图 需要注意的是:线程调用start方法是使得线程到达就绪状态而不是运行状态 2.停止线程的两种方法 1)自然停止:线程体自然执行完毕 2)外部干涉:通过线程体标识 1.线程类中定义线程 ...
- Trusted Cloud Summit(2018.08.14)
时间:2018.08.14地点:北京国际会议中心
- 20155301 Exp4 恶意代码分析
20155301 Exp4 恶意代码分析 实践目标 (1) 是监控你自己系统的运行状态,看有没有可疑的程序在运行. (2) 是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用 ...
- AngularJS+bootstrap-switch 实现开关控件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- mybatis 异常 too many connections 解决方案 mysql
参考: https://blog.csdn.net/u011628250/article/details/54017481 https://www.cnblogs.com/baby123/p/5710 ...
- [CF1007B]Pave the Parallelepiped[组合计数+状态压缩]
题意 \(t\) 组询问,给你 \(A, B, C\) ,问有多少组三元组 \((a, b, c)\) 满足他们任意排列后有: \(a|A,\ b|B,\ c|C\) . \(A,B,C,t\leq ...
- 把Excel的数据导入到数据库
将Excel作为数据源,将数据导入数据库,是SSIS的一个简单的应用,下图是示例Excel,数据列是code和name 第一部分,Excel中的数据类型是数值类型 1,使用SSDT创建一个packag ...
- TensorFlow 训练MNIST数据集(2)—— 多层神经网络
在我的上一篇随笔中,采用了单层神经网络来对MNIST进行训练,在测试集中只有约90%的正确率.这次换一种神经网络(多层神经网络)来进行训练和测试. 1.获取MNIST数据 MNIST数据集只要一行代码 ...
- 软件测试_测试工具_LoadRunner
最近正在逐步学习软件测试工具的使用,此文章也是用来当做笔记以供记录之用.如有问题,还请多多指出. 安装LoadRunner基本步骤从网上搜索即可找到,特此提供部分链接参考(其中附带软件下载): 1.L ...
- CentOS 7 Apache服务的安装与配置
原文出处:http://blog.51cto.com/13525470/2070375 一.Apache简介 Apache 是一个知名的开源Web服务器.早期的Apache服务器由Apache Gro ...