hdu 1597 find the nth digit
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
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
接下来的K行每行有一个整数N(1 <= N < 2^31)。
/*
串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的更多相关文章
- hdu 1597 find the nth digit (数学)
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 【HDOJ】1597 find the nth digit
二分. #include <stdio.h> #include <math.h> int main() { int case_n; double n, tmp, l, r; i ...
- find the nth digit(二分查找)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1597 find the nth digit Time Limit: 1000/1000 MS (Jav ...
- (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] 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 ...
- 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 ...
- [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 ...
- C++版 - Leetcode 400. Nth Digit解题报告
leetcode 400. Nth Digit 在线提交网址: https://leetcode.com/problems/nth-digit/ Total Accepted: 4356 Total ...
随机推荐
- 李洪强iOS开发之XMPP
XMPP历史 这个xmpp框架在2008年开始,不过是一个简单地RFC实现.提供一个最小的代理去接受三种xmpp的基本类型presence.message.iq.因为framwork只提供了最小的 ...
- 初识MyBatis
ORM:对象关系映射,它只是一种规则. 像MyBatis,Hibernate对jdbc进行了封装. 第一章 回顾JDBC开发 1.优点:简单易学,上手快,非常灵活构建SQL(自己写的),效率高.2.缺 ...
- 研究系统IO和glib IO的关系
PS:这里的缓冲与非缓冲的区别是相对于用户进程,下文的“非缓冲文件系统”指用户的程序没有缓冲区,不要误解为系统没有缓冲区. 1.缓冲文件系统缓 冲文件系统的特点是:在内存开辟一个“缓冲区”,为程序中的 ...
- PHP 日期计算函数【差异天数】
function count_days($a,$b){ $a_dt=getdate($a); $b_dt=getdate($b); $a_new=mktime(12,0,0,$a_dt['mon'], ...
- cadence allegro PCB中怎么使查找元件时屏幕不移动
先按F4进入show element状态,你在找元件,屏幕就会移动到你找的元件上面去,并且将视图放大.
- hdu4639Hehe
http://acm.hdu.edu.cn/showproblem.php?pid=4639 统计连续he的数量恰为斐波序列 不同块进行相乘 #include <iostream> #i ...
- SQL Server中Delete语句表名不能用别名
delete from TABLEA A where A.FIELD1=10 (ORACLE适用)delete TABLEA from TABLEA A where A.FIELD1=1 ...
- [原]Unity3D深入浅出 - 脚本开发基础(Scripts)
常用脚本事件: Update:每帧调用一次 Start:在第一次Update执行前调用 Awake:脚本实例在创建时调用 FixedUpdate:每个固定物理时间间隔调用一次 LateUpdate:每 ...
- ShareSDK 实现新浪微博分享(微信,QQ,新浪微博类似)
1 . 分享(前提是集成了sdk,配置好了Key),只要实现点击事件,调用shareSina(); ShareSDK.initSDK(this); private void shareSina() { ...
- Highcharts20151130
$(function () { $('#container').highcharts({ chart: { type: 'spline' // 图的类型 }, title: { text: null ...