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. _bzoj1008 [HNOI2008]越狱【计数】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1008 水题... #include <cstdio> const int mod ...

  2. 计算机视觉-SIFT特征匹配进行目标转换

    Lowe将SIFT算法分解为如下四步: 1. 尺度空间极值检测:搜索所有尺度上的图像位置.通过高斯微分函数来识别潜在的对于尺度和旋转不变的兴趣点. 关键点定位:在每个候选的位置上,通过一个拟合精细的模 ...

  3. C plus plus sprintf用法

    sprintf int sprintf ( char * str, const char * format, ... ); Write formatted data to string Compose ...

  4. Hibernate配置(通过注解配置)

    本文主要讲通过注解配置来替换Hibernate的映射文件 1.多对一配置 package com.jazz7.entity; import java.util.Date; import javax.p ...

  5. JAVA300集笔记

    章节2 java入门阶段 2.1注释 单行注释 //  多行注释 /* 内容*/ 文本注释/**内容*/ 注释是为了方便阅读代码,在编译时注释会被删除. 2.2 标识符 标识符作用: 标识符用来给变量 ...

  6. Activiti工作流和shiro权限管理关系图

  7. 桥接模式和php实现

    桥接模式(Bridge Pattern): 将抽象部分与它的实现部分分离,使它们都可以独立地变化.它是一种对象结构型模式,又称为柄体(Handle and Body)模式或接口(Interface)模 ...

  8. [BZOJ2002][Hnoi2010]Bounce弹飞绵羊 LCT

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 建图,每次往后面跳就往目标位置连边,将跳出界的点设为同一个点.对于修改操作发现可以用 ...

  9. Spring------IOC&DI

    一.Spring? Spring兴起:2003年,由Rod Johnson创建.总的来说,Spring Framwork从它诞生至今都一直为人所称道,它的伟大之处自此可见一斑. 核心:IOC& ...

  10. .NET 微信开发之 获取用户数据

    通过微信接口获取用户信息主要分为以下几个步骤: a.获取公众号的access_token b.通过查询所有用户OPenid接口获取所有用户. string url = "https://ap ...