find the nth digit

                                                                   Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768
K (Java/Others)

                                                                                              Total Submission(s): 11311    Accepted Submission(s): 3378

->  Link  <-

这种题应该是数位dp吧,之前在cf上第一次碰见这种题,此后不断碰到类似变形的,不过poj上那道Number sequense还是没有A出来,这道题和cf上的那道很相似,用的就是类似的思路,不是很难;

思路:既然是1121231234.....9 123..91 123...912 123...91234...,我们观察数字规律,第1位是1,第3位是2,第10位是4,出现第1个9的时候是第45位,也就是说前45位位数n=(1+i)*i/2,类似于前n项和;而45位以后,每出现的一个字串的长度从10开始递增,最低位从1开始到9然后又从1开始到9,直到位数凑够n;

这样说可能有点不明白,还是用代码解释吧:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int i=1;
while(n>i)
{
n-=i;//反过来就是相当于前i项和;
i++;
}
while(n>9) n-=9;//当其位数大于45时,就是上面所说的从1开始排到9又从1开始排到9.......所以。。
printf("%d\n",n);
}
return 0;
}//自己在稿子上模拟一下很好理解的;

要不是在cf上看到那种题这道题还不造要做多久,不得不又感慨一下CF上的题真的很启发思维啊,一道题发散性思维就可以解决很多问题,收获很大,做这道题估计不超过半小时,稍微推一下直接A了,真的好开心!!

HDU-1597find the nth digit,超短代码一遍过,啦啦啦啦~~的更多相关文章

  1. hdu 1597 find the nth digit (数学)

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. hdu 1597 find the nth digit

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. find the nth digit(二分查找)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1597 find the nth digit Time Limit: 1000/1000 MS (Jav ...

  4. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  5. C++版 - Leetcode 400. Nth Digit解题报告

    leetcode 400. Nth Digit 在线提交网址: https://leetcode.com/problems/nth-digit/ Total Accepted: 4356 Total ...

  6. (lower_bound)find the nth digit hdu1597

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. leetcode 400 Add to List 400. Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is ...

  8. Leetcode: Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  9. Nth Digit | leetcode

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

随机推荐

  1. Tree CodeForces -932D

    错误记录:如下注释语句 #include<cstdio> #include<algorithm> using namespace std; typedef long long ...

  2. DB buffer bussy wait 分析一例

    ####sample 1: DB层分析OI DB层分析OI的信息如下: 1. 异常时间段,  Logical reads:/ Physical reads/ Physical write  指标都低于 ...

  3. win7 系统 右键很慢

    一般都是显卡驱动造成的, 在桌面按右键反应慢,通常都是显卡驱动程序惹的祸,最最简单有效的办法就是:开始--运行--. 运行regsvr32 /u igfxpph.dll

  4. HDU 5996 博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=5996 博弈论待补. 这题变化了一下,因为注意到奇数层的东西(层数从1开始),对手可以模仿地动,那就相当于没动. ...

  5. snort + barnyard2如何正确读取snort.unified2格式的数据集并且入库MySQL(图文详解)

    不多说,直接上干货! 为什么,要写这篇论文? 是因为,目前科研的我,正值研三,致力于网络安全.大数据.机器学习研究领域! 论文方向的需要,同时不局限于真实物理环境机器实验室的攻防环境.也不局限于真实物 ...

  6. 记录一下java在后端用request来判断请求类型

    这几天看代码,看到这么一个操作. String requestType = request.getHeader("X-Requested-With");  于是各种查找   这里记 ...

  7. 2019最新Android面试题

    原文链接:https://blog.csdn.net/wen_haha/article/details/88362469版权声明:本文为博主原创文章,转载请附上博文链接! 前言 金三银四到来了,找工作 ...

  8. git push失败the remote end hung up unexpectedly

    Git Push是老是失败,提示: fatal: the remote end hung up unexpectedly git did not exit cleanly (exit code 1) ...

  9. MVC 附件在线预览

    原因:应客户需求,在系统中浏览附件内容,需要先下载到本地然后打开,对使用造成了不便,要求可以不需下载直接在浏览器中打开减少操作步骤. 领导给了3天时间,最后查找方法,写测试项目,往正式项目添加,测试, ...

  10. vb,wps,excel 分裂

    Sub 分列() '以空格为分隔符,连续空格只算1个.对所选中的单元格进行处理 Dim m As Range, tmpStr As String, s As String Dim x As Integ ...