2014年3月11日
摘要: 原题链接#include struct Node{ int begin, end;};Node a[201];int p[401];int main(){ int t, n, i, temp, count, j; scanf("%d", &t); while(t--){ scanf("%d", &n); for(i = 0; i != n; ++i){ scanf("%d%d", &a[i].begin, &a[i].end); if(a[i].begin > a[i].end){ temp = 阅读全文
posted @ 2014-03-11 22:33 长木Qiu 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 原题链接思路:比如说13的阶乘中有多少个3.13!=1*2*3*...*6*...9*...12;其中有多少个数能被3整除呢?答案是13/3=4个。但是答案却是5,为什么,因为9里面有2个3所以是4个.若是100!里面有多少个5?首先看里面有多少个数能被5整除,答案是100/5=20;再看有多少个数能被5*5整除,答案是100/25=(100/5)上面的结果/5,直到除到结果小于5为止,把每个式子的结果相加即为答案。#include int main(){ int t, a, b, count; scanf("%d", &t); while(t--){ scanf( 阅读全文
posted @ 2014-03-11 21:21 长木Qiu 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 原题链接注意要用__int64存和。//2014-3-11 20:31:42#include int main(){ int t, n, max, a; __int64 s; scanf("%d", &t); while(t-- && scanf("%d", &n)){ s = max = 0; for(int i = 0; i != n; ++i){ scanf("%d", &a); if(a > max) max = a; s += a; } if(s - max >= max 阅读全文
posted @ 2014-03-11 20:38 长木Qiu 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 原题链接//二分法2014-3-11 19:10:15#include int f(int a, int b){ if(b == 1) return a; int s = f(a, b / 2); if(b & 1) return s * s * a % 1000; else return s * s % 1000;}int main(){ int a, b; while(scanf("%d%d", &a, &b), a || b){ a %= 1000; printf("%d\n", f(a, b)); } return 0;} 阅读全文
posted @ 2014-03-11 19:16 长木Qiu 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 原题链接很经典的一道题,开始想着用二分法,结果超时,后来发现了规律,就搞定啦。//找规律2014-3-11 18:40:19#include #include char *sam[] = {"0", "1", "2486", "3971", "46", "5", "6", "7931", "8426", "91"};int main(){ int t, n, time; scanf("% 阅读全文
posted @ 2014-03-11 18:52 长木Qiu 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 原题链接//2014-3-11 09:16:50#include #define MAX 1000000int a[MAX] = {1, 2};int main(){ int n; for(n = 2; n != MAX; ++n) a[n] = (a[n - 1] + a[n - 2]) % 3; while(scanf("%d", &n) == 1) printf(a[n] ? "no\n" : "yes\n"); return 0;}优化好的代码://2014-3-11 09:29:47#include int main 阅读全文
posted @ 2014-03-11 09:20 长木Qiu 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 原题链接最小公倍数等于两数之积除以最大公约数。//2014-3-11 09:03:09#include int gcd(int a, int b){ int t; while(b){ t = a % b; a = b; b = t; } return a;}int main(){ int t, n, a, s; scanf("%d", &t); while(t--){ scanf("%d", &n); s = 1; while(n--){ scanf("%d", &a); s = s / gcd(s, a) * 阅读全文
posted @ 2014-03-11 09:10 长木Qiu 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 原题链接注意输出格式,每一组的case都要重新开始计数。//模拟//2014-3-11 08:19:16#include int main(){ int t, n, m, a, b, count, time; scanf("%d", &t); while(t--){ time = 1; while(scanf("%d%d", &n, &m), n || m){ for(a = 1, count = 0; a < n - 1; ++a) for(b = a + 1; b < n; ++b) ... 阅读全文
posted @ 2014-03-11 08:51 长木Qiu 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include char buf[10001];int main(){ int t; char *p, ch; scanf("%d\n", &t); while(t--){ buf[0] = getchar(); p = buf + 1; while((ch = getchar()) != '\n'){ if(ch - 1 == *(p - 1) || ch - 2 == *(p - 1)) --p; else *p++ = ch; } printf(p == buf? "Yes\n": "No\n" 阅读全文
posted @ 2014-03-11 08:43 长木Qiu 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 原题链接问题最后转化成求两个数的最大公约数,如果为1就YES.#include int main(){ int step, mod, t; while(scanf("%d%d", &step, &mod) == 2){ printf("%10d%10d", step, mod); while(mod){ t = step % mod; step = mod; mod = t; } printf(" %s\n\n", step == 1? "Good Choice": "Bad Choice 阅读全文
posted @ 2014-03-11 07:59 长木Qiu 阅读(145) 评论(0) 推荐(0) 编辑