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. IText 生成简单表格(报表)doc文档 单元居中

    IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar 亲测无误,代码如下所示: import com.lowagie ...

  2. 深入理解Java内存模型(二)——重排序

    本文属于作者原创,原文发表于InfoQ:http://www.infoq.com/cn/articles/java-memory-model-2 数据依赖性 如果两个操作访问同一个变量,且这两个操作中 ...

  3. ZOJ Monthly, November 2014

    做了一次月赛,没想到这么难,加上后来补上的题目也只有3个题.第一名也只有4个题啊啊啊啊~.其中两道还是水题.留坑慢慢补上来. 3832 Tilt Cylinder 给定如图所示有盖圆柱体,R,H,水面 ...

  4. Servlet中乱码问题

    页面编码方式为utf-8 当使用post传值时 request.setContentType("utf-8"); 当使用get传值时 String str = request.ge ...

  5. HDMI介绍与流程

    HDMI接口 http://baike.c114.net/view.asp?id=17671-21565442 DDC(Display Data Channel)通道用于HDMI发送和接收端之间交换一 ...

  6. 你不知道的pogo pin连接器

    pogo pin连接器是一种带弹簧的探针式连接器,pogo pin连接器结构看起来非常简单,但其制造工艺要求极其的精细与复杂,从车床加工,电镀,组装等每道工序,如果没有一个有良好品质控制和完善的制造水 ...

  7. 拒绝卡顿——在WPF中使用多线程更新UI

    原文:拒绝卡顿--在WPF中使用多线程更新UI 有经验的程序员们都知道:不能在UI线程上进行耗时操作,那样会造成界面卡顿,如下就是一个简单的示例: public partial class MainW ...

  8. 210. Course Schedule II

    题目: There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have ...

  9. 反汇编(Disassembler) iPhone

    什么是反汇编? 反汇编就是把可执行的二进制文件转为汇编代码,进而可以研究该程序.IDA Pro Adv v5.2 版本起已直接支援 iPhone ARM 代码的静态反汇编分析.IDA Pro Adv ...

  10. SHOI2008小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1139  Solved: 701[Submit][ ...