2014年3月1日
摘要: 原题链接十进制转换成二进制时要注意不足补0,二进制转十进制不需要考虑这种情况。#include #include char str[35], buf[35];void f1(){ int t, i; char *p = strtok(str, "."); buf[8] = '\0'; while(p != '\0'){ sscanf(p, "%d", &t); i = 8; while(t){ buf[--i] = t % 2 + '0'; t /= 2; } while(i) buf[--i] = 阅读全文
posted @ 2014-03-01 23:51 长木Qiu 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题。#include int main(){ int t, m, a, b, temp; scanf("%d", &t); while(t-- && scanf("%d", &m)){ a = 0; while(m-- && scanf("%d", &temp)){ if(!a){ b = temp; a = 1; continue; } if(temp == b) ++a; else{ printf("%d %d ", a, b); a = 1; 阅读全文
posted @ 2014-03-01 23:07 长木Qiu 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 原题链接用C++结果TLE了三次,换成C就过了..时间:744,内存:424#include #include #define MAX 50000 + 2int a[MAX];using namespace std;int main(){ int m, n, i, t, sum; while(scanf("%d%d", &m, &n) == 2){ for(i = 0; i != m; ++i) scanf("%d", &a[i]); sort(a, a + m); for(i = sum = 0; i != n; ++i){ s 阅读全文
posted @ 2014-03-01 21:43 长木Qiu 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include char *str[] = {"East", "South", "West", "North"}, buf[10];int main(){ int s, n, i, t; while(scanf("%s%d", buf, &n) == 2){ s = 0; while(n-- && scanf("%d", &t)) s += (t ? 1 : -1); s %= 4; switch(buf[0]){ case ' 阅读全文
posted @ 2014-03-01 20:54 长木Qiu 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 原题链接数学题,找规律,套公式。#include int main(){ int n; while(scanf("%d", &n) == 1){ if(n & 1) --n; printf("%d\n", n * (2 + n) / 4); } return 0;} 阅读全文
posted @ 2014-03-01 19:34 长木Qiu 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include int main(){ int n; while(scanf("%d", &n), n != -1) if(n == 6) printf("6=1+2+3\n"); else if(n == 28) printf("28=1+2+4+7+14\n"); else if(n == 496) printf("496=1+2+4+8+16+31+62+124+248\n"); else if(n == 8128) printf("8128=1+2+4+8+16+32+64+12 阅读全文
posted @ 2014-03-01 16:08 长木Qiu 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include #include #include int a[100], b[101];int cmp(const void *a, const void *b){ return *(int *)b - *(int *)a;}int main(){ int n, m, i, count, t, j; while(scanf("%d%d", &n, &m) == 2){ if(n == 0 || m == 0) continue; for(i = 0; i != n; ++i) scanf("%d", &a[i]); q 阅读全文
posted @ 2014-03-01 15:04 长木Qiu 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题。#include #include char *samp[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};int main(){ char str[10]; int a = 0, b = 0, ok = 1, i; while(scanf("%s&qu 阅读全文
posted @ 2014-03-01 14:14 长木Qiu 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include int main(){ int n, a[10], i; while(scanf("%d", &n) == 1){ for(i = 0; i != 10; ++i) scanf("%d", &a[i]); for(i = 0; i != 10; ++i){ if(n == 0) break; n += a[i]; } printf("%d\n", i);; } return 0;} 阅读全文
posted @ 2014-03-01 13:54 长木Qiu 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 原题链接暴力枚举。#include #include int main(){ int n, m, *a, i, j, count, t; while(scanf("%d%d", &n, &m) == 2){ count = 0; a = (int *)malloc(sizeof(int) *n); for(i = 0; i != n; ++i) scanf("%d", &a[i]); for(i = t = 0; i != n; ++i, t = 0) for(j = i; j != n; ++j){ t += a[j]; if( 阅读全文
posted @ 2014-03-01 13:34 长木Qiu 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 原题链接很有意思的一道题,刚看题的时候觉得很难,但是仔细一想会发现规律,即找到个数最多的糖果max,只要max小于等于剩下的素有糖果数量+1就Yes,都则No.#include #include int main(){ int t, n, s, *a, max; scanf("%d", &t); while(t-- && scanf("%d", &n)){ a = (int *)malloc(sizeof(int) * n); s = max = 0; for(int i = 0; i != n; ++i){ scanf( 阅读全文
posted @ 2014-03-01 13:16 长木Qiu 阅读(96) 评论(0) 推荐(0) 编辑