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. 简单的回文数,大一肯定有要求写过 ...
随机推荐
- DELPHI语法基础学习笔记-Windows 句柄、回调函数、函数重载等(Delphi中很少需要直接使用句柄,因为句柄藏在窗体、 位图及其他Delphi 对象的内部)
函数重载重载的思想很简单:编译器允许你用同一名字定义多个函数或过程,只要它们所带的参数不同.实际上,编译器是通过检测参数来确定需要调用的例程.下面是从VCL 的数学单元(Math Unit)中摘录的一 ...
- linux 下vi中关于删除某段,某行,或者全部删除的命令
1,先打开某个文件: vi filename 2,转到文件结尾 在命令模式输入 G 转到10行 在命令模式输入 10G 4,删除所有内容:先用G 转到文件尾,然后使用下面命令: :1, ...
- ShareSDK第三方登陆 (IOS)
1.http://www.mob.com/ 注册申请 2.http://www.mob.com/#/download SDK下载 (简洁版:http://www.mob.com/#/download ...
- Windows Service的安装卸载 和 Service控制
原文 Windows Service的安装卸载 和 Service控制 本文内容包括如何通过C#代码安装Windows Service(exe文件,并非打包后的安装文件).判断Service是否存在. ...
- hdu4709求三角形面积
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- CentOS 6.4 x86_64 安装GCC 4.7.3
下载gcc-4.7.3.tar.gz, 解压缩 wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.3/gcc-4.7.3.tar.gz tar -xzvf gcc-4.7. ...
- 引用iscroll的一个封装方法
var Page = function(cid, data,callback) { var _self = this; var cid = $(cid); var currPage=1; // 下拉上 ...
- accept系统调用内核实现
用户态对accept的标准使用方法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_siz ...
- shell telnet 路由器
#!/usr/bin/expect -f spawn telnet 172.16.1.80 expect "login" { send "admin\n" ex ...
- autotools入门笔记(一)
GNU autotools作用:收集系统配置信息并自动生成Makefile文件. GNU autotools主要包括三个工具:autoconf.automake.libtool,还有很多辅助的工具,包 ...