POJ 1019 Number Sequence (二分查找+暴力打表)
2013-07-16 08:48
465 查看
题意:把数字1,12,123,1234,12345,,,,连起来,问第k个数字是多少,原以为最大的数会很大,看了discuss之后发现才30000多点,直接暴力到100000。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <stack> #include <map> #include <string> #define LL long long #define DB double #define SF scanf #define PF printf #define N 100009 #define bug cout<<"bug"<<endl; using namespace std; LL sum ; int re[N*5]; int tmp ; void init() { int cnt=0; int c[10],k; for(int i=1;i<N;i++) { int t = i; k = 0; while(t>0) { c[k++]=t%10; t/=10; } sum[i] = sum[i-1]+tmp[i-1]+k; tmp[i] = tmp[i-1]+k; while(k) { re[cnt++] = c[--k]; } } } int find(LL k) { int l = 0,r=N-1,ret,mid; while(l<=r) { mid = (l+r)>>1; if(sum[mid]>k) { r = mid-1; }else { ret = mid; l = mid+1; } } return ret; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif init(); int n,a; SF("%d",&n); while(n--) { SF("%d",&a); a--; int t = find(a); a-=sum[t]; PF("%d\n",re[a]); } return 0; }
相关文章推荐
- poj1019 Number Sequence 二分+数学+打表
- poj 1019 Number Sequence 打表二分
- poj 1019 Number Sequence(打表+二分)
- POJ-1019 Number Sequence 二分查找
- 【POJ】2002 - Squares(暴力枚举 & 双关键字二分查找)
- 模拟+二分 poj-1019-Number Sequence
- 模拟+二分 poj-1019-Number Sequence
- poj 1019 Number Sequence , 二分
- poj 1019 Number Sequence(dp+二分)
- POJ 1019:Number Sequence 二分查找
- POJ_1019_Number Sequence_二分搜索
- POJ 1019:Number Sequence 二分查找
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
- 【2015ZUFE新生赛网络同步赛M】【DP 打表 二分】GW I (3) 暴力预处理+分类打表二分查找
- POJ 3579 3685(二分-查找第k大的值)
- POJ2785 4 Values whose Sum is 0(暴力二分查找)
- 未懂 POJ 1019 Number Sequence
- XTU 1185 暴力打表+二分
- poj1019 Number Sequence
- POJ 1905 - Expanding Rods(二分查找)