戏雷chnos.blog.chinaunix.net
chnos
全部博文(41)
ACM UVA题(38)
2012年(8)
2011年(1)
2009年(32)
止觞
分类:
2009-04-16 20:32:55
/* ******************************************************************************* * * Filename: 701.c * * Version: 0.1 * * Author: Ye Xiaofeng , yexfeng # gmail.com * ******************************************************************************* */ #include <stdio.h> #include <stdlib.h> #include <math.h> int length(unsigned in) { int len = 0; if (in < 10) { return 1; } else { while (in > 0) { in /= 10; len++; } } return len; } void process(unsigned int in) { int k; int e; double left, right; double log_2; double log_10; double d1; double d2; double d3; double d4; log_2 = log(2); log_10 = log(10); d1 = log(in) / log_2; d2 = log_10 / log_2; d3 = log(in+1) / log_2; d4 = log_10 / log_2; k = length(in) + 1; left = d1 + k * d2; right = d3 + k * d4; e = (int)ceil(left); while (e >= right) { k++; left = d1 + k * d2; right = d3 + k * d4; e = (int)ceil(left); } printf("%d\n", e); } int main(int argc, char *argv) { unsigned int in; while (scanf("%u", &in) != EOF) { process(in); } return 0; }
上一篇:ACM UVA (400)
下一篇:ACM UVA (10004)
登录 注册