| ||||||||||
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 |
哈尔滨现场赛 1006 问题哈尔滨现场赛的一个题目 Simple Addition Expression http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1006&cid=155 各位大牛,能不能帮我看看`````我写的代码,用穷举的方法校验, 所有数据都校验了一遍``````死活都没搜出问题```谢谢大家了 这个是我的代码 #include <stdio.h> #include <string.h> int pow4[11] = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576}; int pow_10[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; int f(int n, int len) { char tmp[20]; sprintf(tmp, "%d", n); if(len == 1) { if(n > 2) return 3; return n; } if(strlen(tmp) < len) return f(n, strlen(tmp)); if(n / pow_10[len - 1] > 3) return pow4[len - 1] * 3; return f(n % pow_10[len - 1], len - 1) + (n / pow_10[len - 1]) * pow4[len - 2] * 3; } int main() { int n; int count; n = 0; count = -1; //freopen("out", "w", stdout); while(scanf("%d", &n) != EOF)//++n <= 1000000000) { char tmp[20]; int len; sprintf(tmp, "%d", n); len = strlen(tmp); /*if(count != f(n, len)) { count = f(n, len); printf("%d %d\n", n, count); }*/ printf("%d\n", f(n, len)); } return 0; } 这个是我用来穷举校验的代码 #include <stdio.h> int main() { int i, count = 0; freopen("out1", "w", stdout); for(i = 0; i <= 1000000000; i++) { int j; j = i; if(j % 10 > 2) continue; j /= 10; while(j) { if(j % 10 > 3) break; j /= 10; } if(!j) { count++; printf("%d %d\n", i + 1, count); } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator