POJ1019分块
来源:互联网 发布:房屋框架设计软件 编辑:程序博客网 时间:2024/05/01 07:25
查询数
11212312341234512345612345671234567812345678912345678910123456789101112345678910.......
第n(<= 2147483647)个数字是多少。
分块思想:
typedef long long LL ;const int maxn = 40000 ;LL sum[maxn+8] , x[maxn+8] ;int main(){ int i , j ; sum[0] = x[0] = 0 ; for(i = 1 ; i <= 9 ; i++) x[i] = x[i-1] + 1 ; for(i = 10 ; i <= 99 ; i++) x[i] = x[i-1] + 2 ; for(i = 100 ; i <= 999 ; i++) x[i] = x[i-1] + 3 ; for(i = 1000 ; i <= 9999 ; i++) x[i] = x[i-1] + 4 ; for(i = 10000 ; i <= 40000 ; i++) x[i] = x[i-1] + 5 ; for(i = 1 ; i <= 40000 ; i++) sum[i] = sum[i-1] + x[i] ; int t ; LL n ; cin>>t ; while(scanf("%lld" , &n) != EOF){ i = lower_bound(sum , sum+40000 , n) - sum ; n -= sum[i-1] ; i = lower_bound(x , x+i+1 , n) - x ; n -= x[i-1] ; vector<int> dig ; dig.clear() ; while(i){ dig.push_back(i % 10) ; i /= 10 ; } std::reverse(dig.begin() , dig.end()) ; cout << dig[n-1] << endl ; } return 0 ;}
0 0
- POJ1019分块
- poj1019 大数据处理 分块
- POJ1019
- POJ1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- poj1019
- ArcServer 10.1 发布GP工具
- MySQL 时间日期相关
- 基于OpenCV的图像去雾程序
- 北京微图科技
- JAVA保留小数点
- POJ1019分块
- STL系列之一 deque双向队列
- Linux下安装JDK1.6及eclipse
- Java实现简单链表
- Android内存泄漏分析及调试
- Unhandled exception type SQLException 异常
- 【 D3.js 入门系列 --- 4 】 如何使用scale(比例)
- mac There are no interface on Which a capture can be done
- 10大基础实用算法