cf 1216e1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf 1216e1相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/ems' title='ems'>ems
鏁板瓧 mes lse cli name def names problemhttps://codeforc.es/problemset/problem/1216/E1
姹?121231234...搴忓垪閲岄潰绗琸涓暟瀛楋紝k涓嶈秴杩?0浜裤€?nbsp;
鎴戜滑鍙棰勫鐞嗕竴涓猻um鏁扮粍锛岀劧鍚庢瘡娆′簩鍒嗕竴涓嬶紙鍏跺疄涓嶄簩鍒嗕篃鍙互锛?nbsp;
1 #include <bits/stdc++.h> 2 using namespace std; 3 int const inf = 1e9; 4 int q, sum[100000], pw[10]; 5 int num(int x) 6 { 7 int res = 0; 8 while (x) 9 { 10 x /= 10; 11 res++; 12 } 13 return res; 14 } 15 int query(int t, int x) 16 { 17 while (1) 18 { 19 x--; 20 if (x == 0) 21 return t % 10; 22 t /= 10; 23 } 24 } 25 int main() 26 { 27 scanf("%d", &q); 28 int s = 0, n; 29 pw[0] = 1; 30 for (int i = 1; i < 10; i++) 31 pw[i] = pw[i - 1] * 10; 32 for (int i = 1;; i++) 33 { 34 s += num(i); 35 sum[i] = sum[i - 1] + s; 36 if (sum[i] >= inf) 37 { 38 n = i; 39 break; 40 } 41 } 42 while (q--) 43 { 44 int x; 45 scanf("%d", &x); 46 int l = 1, r = n; 47 while (l < r) 48 { 49 int mid = (l + r) / 2; 50 if (sum[mid] >= x) 51 r = mid; 52 else 53 l = mid + 1; 54 } 55 x -= sum[r - 1]; 56 for (int i = 1; i < 10; i++) 57 { 58 int tmp = (pw[i] - pw[i - 1]) * i; 59 if (x > tmp) 60 x -= tmp; 61 else 62 { 63 int t = pw[i - 1] + (x - 1) / i; 64 x = (x - 1) % i + 1; 65 printf("%d ", query(t, i - x + 1)); 66 break; 67 } 68 } 69 } 70 return 0; 71 }
以上是关于cf 1216e1的主要内容,如果未能解决你的问题,请参考以下文章