HDU-1597find the nth digit,超短代码一遍过,啦啦啦啦~~
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,超短代码一遍过,啦啦啦啦~~的更多相关文章
- hdu 1597 find the nth digit (数学)
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1597 find the nth digit
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- find the nth digit(二分查找)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1597 find the nth digit Time Limit: 1000/1000 MS (Jav ...
- [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 ...
- C++版 - Leetcode 400. Nth Digit解题报告
leetcode 400. Nth Digit 在线提交网址: https://leetcode.com/problems/nth-digit/ Total Accepted: 4356 Total ...
- (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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- ACM_回文素数
回文素数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 131号是一个主回文,因为它是一个素数和一个回文(当向后读时,它是相同的 ...
- ACM_绝对值
100块钱都不给我 Time Limit: 2000/1000ms (Java/Others) Problem Description: 今天是广财的ACM周赛,小光来到广财实验楼,想来蹭一下素拓分( ...
- Maven环境搭建操作记录
Maven官方网站: http://maven.apache.org/index.html Maven下载地址: http://maven.apache.org/download.cgi Maven历 ...
- windows8.1专业版 关闭ie11总是已停止工作
该问题通常原因: 1 系统重病毒: 2 系统和安装的软件不兼容导致. 解决方案: 1 杀毒更新至最新进行杀毒,仍未解决,重新安装系统: 2 目前身边人员多数属于该情况: 1 如安装了输入法.迅雷或其它 ...
- android开发学习 ------- 【转】Gradle相关
一直在用AndroidStudio,但是对于其Gradle了解的很少. 推荐 http://www.jianshu.com/p/9df3c3b6067a 觉得说的很棒!
- AJPFX关于数组获取最值的思路和方法
思路分析:1.定义一个变量(max,初始值一般为数组中的第一个元素值),用来记录最大值.2.遍历数组,获取数组中的每一个元素,然后依次和max进行比较.如果当前遍历到的元素比max大,就把当前元素值给 ...
- [BZOJ2456]mode 其它
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2456 这道题有着神奇的内存限制1MB也就是说我们是没办法把读入的数字存下来的. 由于答案求 ...
- 用nowrap实现div内的元素不换行
在编写自定义插件my-slider的过程中,发现无论float还是inline-block均不能保证div内的内容不换行(这两个属性在内容超出容器尺寸后,均将剩余内容做换行处理),在浏览器内比较了自己 ...
- CCF|跳一跳
import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner scan ...
- cut - 在文件的每一行中提取片断
总览 (SYNOPSIS) ../src/cut [OPTION]... [FILE]... 描述 (DESCRIPTION) 在 每个文件 FILE 的 各行 中, 把 提取的 片断 显示在 标准输 ...