hd 1597 find the nth digit(解决超时的牛气哄哄的新办法)
来源:互联网 发布:淘宝卖家怎么提高销量 编辑:程序博客网 时间:2024/05/17 13:14
<h1 style="COLOR: #1a5cc8"><div class="panel_title" align="left"><h1 style="COLOR: #1a5cc8">find the nth digit</h1></div><span size="+0"><strong><span style="font-family:Arial;font-size:12px;color:green;FONT-WEIGHT: bold">Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8385 Accepted Submission(s): 2394</span></strong></span></h1><div class="panel_title" align="left">Problem Description</div><div class="panel_content">假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 1234567891S11 = 12345678912............S18 = 123456789123456789..................现在我们把所有的串连接起来S = 1121231234.......123456789123456789112345678912.........那么你能告诉我在S串中的第N个数字是多少吗?</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Input</div><div class="panel_content">输入首先是一个数字K,代表有K次询问。接下来的K行每行有一个整数N(1 <= N < 2^31)。</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Output</div><div class="panel_content">对于每个N,输出S中第N个对应的数字.</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="FONT-FAMILY: Courier New,Courier,monospace">61234510</div>
Sample Output
112124
Author
8600
Source
HDU 2007-Spring Programming Contest - Warm Up (1)
Recommend
#include<stdio.h>//#include<iostream>#include<math.h>//using namespace std;int main(){ __int64 n,t,i,s,p; scanf("%d",&t); while(t--) { scanf("%I64d",&n); for(i=(int)sqrt(n*2)-1;;i++) { if(i*(i+1)/2>=n) { p=i; break; } } s=(p-1)*p/2; if(n>s) n-=s; while(n>9) { n-=9; } printf("%d\n",n); }return 0; }//加上限制条件i<n试试,不要想当然,多思 //注意初始限制条件i=sqrt(n*2)-1;//超时时如果确认过程正确的话试着把iint 改__int64 下,所有的变量都改着试试
0 0
- hd 1597 find the nth digit(解决超时的牛气哄哄的新办法)
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- HDOJ-1597find the nth digit
- hdu Problem - 1597 find the nth digit
- HDU 1597 find the nth digit
- 1597—find the nth digit
- hdu 1597 find the nth digit
- Hdu 1597 find the nth digit
- hdu 1597 find the nth digit
- hdu 1597 find the nth digit
- 矢量切片技术的应用-大量点数据显示性能问题
- 背包之01背包、完全背包、多重背包详解
- __gnu_cxx::hash_map死循环分析
- Android学习总结之WIN上搭建环境
- php魔法函数__autoload用法
- hd 1597 find the nth digit(解决超时的牛气哄哄的新办法)
- 二十条用电脑技巧看后对大家有好处——————【Badboy】
- You can Solve a Geometry Problem too
- hdu 4952 Number Transformation 多校八 数论
- Crane(线段树)
- 安装及使用grunt
- AndroidAnnotations框架
- ctags, cscope, taglist
- HTML5边玩边学(3):像素和颜色