POJ 1019.Number Sequence
来源:互联网 发布:linux lspci输出 编辑:程序博客网 时间:2024/05/22 07:00
题目:http://poj.org/problem?id=1019
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100105using namespace std;unsigned a[31269];unsigned s[31269];void table(){a[0] = 0;s[0] = 0;a[1] = 1;s[1] = 1;int len;int tmp;for(int i = 2; i <= 31268; i++){len = 0;tmp = i;while(tmp!=0){tmp/=10;len++;}a[i] = a[i-1] + len;s[i] = s[i-1] + a[i];}}int main(){table();int t;cin>>t;while(t--){int n;cin>>n;int pos = 1;while(s[pos]<n)pos++;int m = n-s[pos-1];int len;int tmp;for(int i = 1;;i++){len = 0;tmp = i;while(tmp!=0){tmp/=10;len++;}if(m-len>0)m-=len;else{len-=m;for(int j = 0; j < len; j++)i/=10;cout<<i%10<<endl;break;}}}}总结: 个人认为题意没有表达清楚, 题目的意思是, 给定n, 则输出在数字序列
1,12,123,1234,12345,123456,1234567,12345678,123456789,12345678910,1234567891011,....
中的第n位数, 比如n=3时输出2, n=56时输出12345678910中的0. 思路很简单, 先将序列分组, 打表求出到每组时已经出现了多少位数, 以此找到n所在的组数. 求出所在组数后再暴力解ok了. 至于31269这个数字, 是网上dalao证得的n为2147483647时的最大组数, 为了不让最大组的位数超过int范围, 所以用unsigned来表示.
阅读全文
0 0
- POJ 1019.Number Sequence
- POJ 1019 Number Sequence
- POJ 1019 Number Sequence
- poj 1019 Number Sequence
- poj 1019 Number Sequence
- POJ 1019 Number Sequence
- poj 1019 Number Sequence
- POJ-1019 Number Sequence
- poj Number Sequence
- POJ 1019 Number Sequence
- poj 1019 Number Sequence
- poj 1019 Number Sequence
- POJ 1019 Number Sequence
- poj 1019 Number Sequence
- POJ 1019 Number Sequence
- POJ 1019 Number Sequence
- poj 1019 Number Sequence
- POJ 1019 Number Sequence
- linux跟xftp相连
- mybatis——学习笔记
- 陪陪来了项目苹果端有问题可以留言
- How to write rebuttal ?
- 机器人走格子
- POJ 1019.Number Sequence
- iOS 基础知识--static,const,extern关键字用法
- 在实践中深入理解IP协议
- HttpClient 操作工具类---
- MySQL模拟Oracle序列sequence
- 菜单页面
- iOS 屏幕垂直同步 详解
- Android系统架构篇
- dubbo-rpc分析