Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
直接暴力解,变量不太好看。。。第一次贴#include<stdio.h> #define MAX 500000 int rank; long long a[MAX+1],b[MAX+1]; int aim; void binary_search(int s, int t) { if (s==t) { aim = s; return; } if (s == t - 1) { if (rank <= b[s])aim = s; else aim = t; return; } int mid = (s + t) / 2; if (rank>b[mid-1]&&rank<=b[mid]) { aim = mid; return; } else if (rank > b[mid]) { binary_search(mid + 1, t); } else { binary_search(s, mid - 1); } } int main() { int i, j; int shi = 10, interval = 1; b[0] = 0; a[0] = 0; for (i = 1; i <= MAX; i++) { a[i] = a[i - 1] + interval; b[i] = b[i - 1] + a[i]; if ((i + 1) % shi == 0) { shi *= 10; interval++; } } int test_num; int nine; int wei, num, ppp, kkk; scanf_s("%d", &test_num); for (i = 0; i < test_num; i++) { scanf_s("%d", &rank); binary_search(0, MAX); rank -= b[aim - 1]; nine = 9; j = 1; while (rank > a[nine] && nine <= aim) { nine = nine * 10 + 9; j++; } rank -= a[nine / 10]; wei = (rank - 1) % j; wei = j - wei; num = (rank - 1) / j; ppp = 1; while (j > 1) { ppp *= 10; j--; } ppp += num; kkk = 1; while (wei > 0) { kkk *= 10; wei--; } printf("%d\n", (ppp%kkk) / (kkk / 10)); } //system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator