Palindrome Numbers(LA2889)第n个回文数是?
J - Palindrome Numbers
Time
Limit:3000MS Memory Limit:0KB 64bit
IO Format:%lld & %llu

。。。。
寻找&星空の孩子#include<stdio.h>
#define LL long long
#define MM 2000000000
LL num[25]= {0};
LL ppow(LL x,LL y)
{
LL tp=1;
while(y--)
{
tp*=x;
}
return tp;
} void init()
{
LL tp=9,i;
for(i=1;;)
{
num[i]=num[i-1]+tp;
i++;//同行有多个i要处理的时候i,不要把i++放里面,由于变异环境不同。运算顺序不同,可能会wa
num[i]=num[i-1]+tp;
i++;
tp=tp*10;
if(num[i-1]>=MM)break;
} /* for(int i=1;i<21;i++)
{
LL p=(i+1)/2-1;
num[i]=num[i-1]+9*ppow(10,p);
// printf("%lld\n",num[i]);
}
// printf("%lld\n",num[0]);*/
} int main()
{
init();
LL n;
LL a[20];
while(scanf("%lld",&n),n)
{
int len=0;
for(int i=1; i<=20; i++)
{
if(n<=num[i])
{
len=i;
break;
}
}
// printf("len=%d\n",len);
LL m=n-num[len-1];
int l=(len+1)/2;
// printf("m=%lld\tl=%d\n",m,l);
LL ans=ppow(10,l-1)+m-1;
// printf("ans=%lld\tppow=%lld\n",ans,ppow(10,l-1));
printf("%lld",ans);
if(len&1) ans/=10;
while(ans)
{
printf("%lld",ans%10);
ans/=10;
}
printf("\n");
}
return 0;
}
Palindrome Numbers(LA2889)第n个回文数是?的更多相关文章
- POJ 2402 Palindrome Numbers(LA 2889) 回文数
POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...
- 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 ...
- 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 ...
- leetcode4 Valid Palindrome回文数
Valid Palindrome回文数 whowhoha@outlook.com Question: Given a string, determine if it is a palindrome, ...
- Palindrome 回文数
回文数,从前到后,从后到前都一样 把数字转成字符串来处理 package com.rust.cal; public class Palindrome { public static boolean i ...
- Leetcode 3——Palindrome Number(回文数)
Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...
随机推荐
- HDU3572_Task Schedule(网络流最大流)
解题报告 题意: 工厂有m台机器,须要做n个任务.对于一个任务i.你须要花费一个机器Pi天,并且,開始做这个任务的时间要>=Si,完毕这个任务的时间<=Ei. 对于一个任务,仅仅能由一个机 ...
- EasyUI - ComboBox 下拉组件
效果: html代码: <input id ="comb" name ="comb"/> JS代码: $(function () { $('#com ...
- QT中.pro文件的写法
QT中.pro文件的写法 qmake 变量 含义 #xxxx 注释, 从“#”开始,到这一行结束 SOURCES 指定源文件 SOURCES = *.cpp 对于多源文件,可用空格分开 SOURC ...
- [转载]关于网传JDK1.7语法层次支持集合的问题
以 JDK1.7新特性 为关键词进行百度的话,总能发现这样的描述,说: 从语法层面上支持集合,不再是数组的专利.还有这样的例子: final List<Integer> piDigits ...
- 1.0.1-学习Opencv与MFC混合编程之---播放AVI视频
资源源代码:http://download.csdn.net/detail/nuptboyzhb/3961639 版本1.0.1新增内容 Ø 新建菜单项,Learning OpenCV——> ...
- Oracle性能分析7:创建索引
在创建索引时,我们往往希望可以预估索引大小,以评估对现有project环境的影响,我们也希望创建索引的过程可以最小化的影响我们正在执行的project环境,并能查看索引的状况. 预估索引大小 预估索引 ...
- 使用JDBC进行数据库的事务操作(2)
本篇将讲诉如何使用JDBC进行数据库有关事务的操作.在上一篇博客中已经介绍了事务的概念,和在MySQL命令行窗口进行开启事务,提交事务以及回滚事务的操作. 似乎事务和批处理都可以一次同时执行多条SQL ...
- oracle逗号字符串拼接小工具
oracle逗号字符串拼接小工具 http://www.zui#dai#ma.com/share/1932670249667584.htm 在使用oracle进行数据查询时,常常需要使用到in语句,如 ...
- UIPageControl的一个Demo
本篇文章只是记录了一个自定义UIPageControl 的制作,其实很简单的 源码在底部会奉上链接,还望多多交流,多多支持. 首先效果图如下: 首先先做一个UISCrollView // 建议这样 ...
- ASP.NET - 在线编辑器(KindEditor)
效果: 项目结构: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...