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 |
蒟蒻的AC纪念#include <stdio.h> #include <ctype.h> #define elif else if const int maxn = 276; int Myscan(float *n) { int t; int power = 1; *n = 0; while ((t=getchar()) != EOF && isdigit(t)) *n = *n * 10 + t - '0'; if (t=='.') { while ((t=getchar()) != EOF && isdigit(t)) { *n = *n * 10 + t- '0'; power *= 10; } *n /= power; } return 1; } int BinSearch(int low, int high, float x, float f[]) { int mid; while (low <= high) { mid = (low+high)>>1; if (x <= f[mid-1]) high = mid-1; elif (x > f[mid]) low = mid; if ( x > f[mid-1] && x <= f[mid]) return mid; elif ( x > f[mid] && x <= f[mid+1]) return mid+1; } } int main() { float f[maxn]; int i; f[0] = 0; for (i = 1; i<=maxn; i++) f[i] = f[i-1] + 1/(float)(i+1); float n; while (Myscan(&n) && n != 0) printf("%d card(s)\n", BinSearch(1,maxn,n,f) ); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator