hihocoder#1349 : Nature Numbers(思维)
来源:互联网 发布:php批量执行sql 编辑:程序博客网 时间:2024/06/11 21:41
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
- 样例输入
17
- 样例输出
3
描述
Consider the following sequence S which is constrcuted by writting nature numbers one by one: "012345678910111213...".
The first digit of S, S[0], is 0. The second digit S[1] is 1. And the 11th digit S[10] is 1.
Given an integer N, can you find the digit S[N]?
输入
An integer N. (0 <= N <= 1018)
输出
Digit S[N].
#include<bits/stdc++.h>using namespace std;int main(){long long n,s,num,i,ans;cin>>n;if(n==0)puts("0");else { s=0,num=9,i=1;//i代表位数,num代表i位数有多少个 while(n>=s+num*i) { s+=num*i; i++; num*=10; } n-=s; num=(num/9)-1; num+=n/i;//num代表s[n]所在的整数 n%=i; if(n==0)printf("%d\n",num%10); else { num++; stack<int>p; while(num)p.push(num%10),num/=10; while(n) { ans=p.top(); p.pop(); n--; } cout<<ans<<endl; } }return 0;}
阅读全文
1 0
- hihocoder#1349 : Nature Numbers(思维)
- hihocoder上第180周《Nature Numbers》
- hiho 180 Nature Numbers
- hiho一下 第180周 Nature Numbers
- Nature Numbers hiho一下 第180周
- HihoCoder-1523(思维)
- (简单思维)HihoCoder
- Number of numbers [思维]
- HDU_6170 Numbers 【MAP&&思维】
- HDU 6168 Numbers 思维
- HDU 6168 Numbers 思维
- hihocoder week 86 Spring Outing【思维】
- hihoCoder #1284 : 机会渺茫(思维,数学)
- hihocoder 1284 机会渺茫(GCD+思维)
- hihocoder 1523 数组重排2 思维
- hihocoder 1509 异或排序 二进制思维
- hihocoder 1326 dp OR 思维+枚举
- Hihocoder 1580 Matrix【思维+Dp+RMQ】
- lua-将数据插入table,并设置Key值
- Django 静态文件引用
- 基于MPI和CUDA的三维各向同性二阶声波方程有限差分地震正演模拟(差分部分来自Madagascar)
- MVC Controller相关技术
- linux 学习笔记(二)
- hihocoder#1349 : Nature Numbers(思维)
- warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
- 使用Redis做MyBatis的二级缓存
- 机器学习02之BP神经网络图解及JAVA实现
- 牛客 题库 函数调用约定(calling convention)
- @RequestParam,@PathParam,@PathVariable等注解区别
- socket细节之setsockopt
- PCL源码剖析之MarchingCubes算法
- 爱情小观点