题目链接: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【数论】的更多相关文章

  1. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  2. UVa 12050 - Palindrome Numbers (回文数)

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...

  3. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  4. 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 ≤ ...

  5. UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

      Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people e ...

  6. UVa 10006 - Carmichael Numbers

    UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...

  7. Palindrome Numbers(LA2889)第n个回文数是?

     J - Palindrome Numbers Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  8. 2017ecjtu-summer training #1 UVA 12050

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...

  9. UVa - 12050

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

随机推荐

  1. ES6作用域和解构赋值

    ES6 强制开启严格模式 作用域 var 声明局部变量,for/if花括号中定义的变量在花括号外也可访问 let 声明的变量为块作用域,变量不可重复定义 const 声明常量,块作用域,声明时必须赋值 ...

  2. 商城项目回顾整理(二)easyUi数据表格使用

    后台主页: 商品的数据表格展示 引入用户表数据表格展示 引入日志表数据表格展示 引入订单表数据表格展示 后台主页代码: <%@ page language="java" co ...

  3. #ifdef #else #endif #if #ifndef 的用法

    预编译就是在对源文件进行处理之前(如在语法扫描和分析之前),先处理预处理部分,精简代码,然后再进行编译. 预处理命令有:#include 文件包含.#define 宏定义.以及要重点讲的#if.#if ...

  4. 【Zookeeper】源码分析之服务器(一)

    一.前言 前面已经介绍了Zookeeper中Leader选举的具体流程,接着来学习Zookeeper中的各种服务器. 二.总体框架图 对于服务器,其框架图如下图所示 说明: ZooKeeperServ ...

  5. geoserver发布地图服务WMS

    wms服务发布: 1.打开geoserver管理首页(网址为http://localhost:8080/geoserver/web/),并使用安装时设置的帐户名和密码登录(这里是admin/geose ...

  6. 搭建eclipse+tomcat开发环境

    JDK 1.6 Eclipse IDE For JEE Version Tomcat 6.0 tomcatPluginV33  //eclipse平台上的插件,但它并不是tomcat本身,需要安装独立 ...

  7. Linux根目录详解-转自鸟哥的私房菜

    转自:http://myhat.blog.51cto.com/391263/107931/   *根目录(/)的意义与内容: 根目录是整个系统最重要的一个目录,因为不但所有的目录都是由根目录衍生出来的 ...

  8. 微信公众号H5支付遇到的那些坑

    简史 官方文档说的很清楚,商户已有H5商城网站,用户通过消息或扫描二维码在微信内打开网页时,可以调用微信支付完成下单购买的流程. 当然,最近微信支付平台也加入了纯H5支付,也就是说用户可以在微信以外的 ...

  9. leetcode — linked-list-cycle-ii

    /** * Source : https://oj.leetcode.com/problems/linked-list-cycle-ii/ * * Given a linked list, retur ...

  10. Yii 框架学习--03 多应用多模块

    本文以YII 2.0.7为例. 概述 首先看看多应用和多模块的特点: 多应用的特点: 独立配置文件 独立域名 多模块的特点: 统一配置文件 统一域名 那么,实际该怎么决定使用多应用还是多模块呢? 对于 ...