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. JDK常用类解读--StringBuffer、StringBuilder

    上一篇博客讲到String对象一旦被创建该内容就不能被修改了如: String s = "hello world"; s.substring(6); s.replace(" ...

  2. AJPFX关于java数组排序

    /**         *将数组中的两个指定下标的元素交换位置                   *@param arr 要交换元素的数组引用地址值         *@param a 数组索引  ...

  3. (四)SpringIoc之Bean装配

    在pom.xml的依赖 <dependencies> <!--测试包--> <dependency> <groupId>junit</groupI ...

  4. 数据库text字段存值用回车分隔

    //查询 $sql = "SELECT attr_values FROM ecs_attribute WHERE attr_id=197"; $param_sel_sms = ar ...

  5. iOS---UICollectionView详解和常用API翻译

    UICollectionView 1.必须要设置布局参数 2.注册cell 用法类似于UITableView 类.自动实现重用,必须注册初始化. 使用UICollectionView必须实现UICol ...

  6. 20面向对象三特征 之继承 方法重写 super

    继承是:多个类有重复内容,把重复内容放到一个新类中,就可以通过extends关键词去让原来的类和新类产生继承关系,子类只能拿到父类一部分信息.通过extends关键词去指明类与类之间的关系,一个父类可 ...

  7. JavaSE-05 数组

    学习要点 数组的基本用法 数组的典型应用 数组相关概念 问题 Java考试结束后,老师给小强分配了一项任务,让他计算全班(30人)的平均分,按照目前的知识结构,如何实现? 问题分析 数组 定义:数组是 ...

  8. PageOffice NET MVC下使用

    1)下载官方demo http://www.zhuozhengsoft.com/dowm/ 2)选择此项下载 3)官方demo暂时还未修改支持42版本以上的谷歌浏览器 所以需要修改以下部分 /home ...

  9. fastclick.js插件使用

    引入插件步骤 ①在HTML页面中添加  <script type='application/javascript' src='/path/to/fastclick.js'></scr ...

  10. [JOYOI] 自然数拆分Lunatic版

    题目背景 话说小小鱼看了P1171(自然数拆分)之后感觉异常不爽,于是异常邪恶地将题目加强. 题目描述 输入自然数n,然后将其拆分成由若干数相加的形式,参与加法运算的数可以重复. 输入格式 输入只有一 ...