find the nth digit

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9836    Accepted Submission(s): 2881

Problem Description
假设:
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
 
Input
输入首先是一个数字K,代表有K次询问。
接下来的K行每行有一个整数N(1 <= N < 2^31)。
 
Output
对于每个N,输出S中第N个对应的数字.
 
Sample Input
6
1
2
3
4
5
10
 
Sample Output
1
1
2
1
2
4

/*
串S的长度为S=1+2+3+4+...+n
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
__int64 i,j,k,l,m,n,t;
int main()
{
scanf("%I64d",&k);
while(k--)
{
scanf("%I64d",&n);
for(i=1;;i++)
if(i*(i+1)/2>=n) //先求出n所在的位置是位于S串中第几部分(第一部分是S1=1,第二部分是S2=12第三部分是S3=123)
//以此类推(i*(i+1)=1+2+3+...+i)
break;
m=n-i*(i-1)/2; //i*(i-1)/2为除Si串外其前边所有串的长度
//m为Si串中所要求的位置
m%=9; //因为每9个数循环一次所以求m%9的结果
if(m==0)
m=9;
printf("%I64d\n",m);
}
}

  

  

hdu 1597 find 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. 【HDOJ】1597 find the nth digit

    二分. #include <stdio.h> #include <math.h> int main() { int case_n; double n, tmp, l, r; i ...

  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. (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 ...

  5. [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 ...

  6. 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 ...

  7. 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 ...

  8. [Swift]LeetCode400. 第N个数字 | 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 ...

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

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

随机推荐

  1. xcode 开发ios兼容性问题的上下黑边 和 coco2d-x 游戏分辨率适配 ResolutionPolicy::FIXED_WIDTH 都会引起上下黑边问题!!!

    1:Xcode6在iPhone5+iOS7模拟器上编译,上下有黑边问题 问题描述: Xcode6环境下,对iPhone5或iPhone5s模拟器,在iOS7或iOS7.1下运行,屏幕上下有黑边.在iO ...

  2. spring aop环绕通知

    [Spring实战]—— 9 AOP环绕通知   假如有这么一个场景,需要统计某个方法执行的时间,如何做呢? 典型的会想到在方法执行前记录时间,方法执行后再次记录,得出运行的时间. 如果采用Sprin ...

  3. 【转】win7如何设置共享目录,并且访问不需要输入用户名和密码。

    1.打开guest帐号,guest帐号默认情况下是不启用的 进入控制面板->用户帐户->管理其他帐户->激活Gust用户 2,右击共享目录,属性->共享->共享-> ...

  4. Android 签名(3)已签名的apk中的文件

    已经签名 apk包中签名相关的文件在meta_INF目录下 CERT.SF:生成每个文件相对的密钥 MANIFEST.MF:数字签名信息 xxx.SF:这是JAR文件的签名文件,占位符xxx标识了签名 ...

  5. awesome-java

    Awesome Java A curated list of awesome Java frameworks, libraries and software. Awesome Java Ancient ...

  6. uva 489 Hangman Judge(水题)

    题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  7. struts2启动报错com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1

    好久没有搞struts2,今天配置strut2.2.1,启动时遇到个小问题.记录下. tomcat启动报错: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  8. Exel 利用模板导出方法

    #region Exel导出方法 [MaxuniAuthAttribute(Roles = "sysroles")] public void OrderExport(string ...

  9. tar 命令打包,除了某个目录剩下的都打包

    tar czvf beifen.tar.gz  ./webdata  --exclude webdata/uploadfiles

  10. 学习面试题Day07

    1.打印出100以内的素数 该编程题的思路大致如下: (1)完成一个判断某整数是否为素数的方法: (2)循环1--100: (3)每循环一次就判断一次,返回true则打印:package com.ex ...