2014年2月12日
摘要: 原题链接二元一次方程 a*x+b*y=n,n为a,b的最大公约数的整数倍即有解附ac代码:#include int main(){ int t, a, b, n, x; scanf("%d", &t); while(t-- && scanf("%d%d%d", &a, &b, &n)){ while(b){ x = a % b; a = b; b = x; } if(n % a) printf("No\n"); else printf("Yes\n"); } retu 阅读全文
posted @ 2014-02-12 23:44 长木Qiu 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 原题链接盗梦空间这个电影我看了三遍。good!附ac代码:#include #include double cal(int t, int lev){ //接受分钟,返回秒 double s = t; s *= 60; while(lev--) s /= 20; return s;}int main(){ int t, n, lev, temp; double time; char s[5]; scanf("%d", &t); while(t-- && scanf("%d", &n)){ lev = 0; time = 0; 阅读全文
posted @ 2014-02-12 21:43 长木Qiu 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 原题链接大水题。附ac代码:#include #include int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int t, n; scanf("%d", &t); while(t-- && scanf("%d", &n)){ int *a = (int *)malloc(sizeof(int) * n); int i = 0; while(i < n) scanf("%d", &am 阅读全文
posted @ 2014-02-12 21:18 长木Qiu 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题。附ac代码:#include int T[302];int main(){ int t, n, s, i, j = 1; for(i = 1; i != 302; ++i) T[i] = T[i - 1] + i; scanf("%d", &t); while(t-- && scanf("%d", &n)){ s = 0; for(i = 1; i <= n; ++i) s += i * T[i + 1]; printf("%d %d %d\n", j++, n, s); } re 阅读全文
posted @ 2014-02-12 21:04 长木Qiu 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 原题链接开始把题意看错了,把数组多开了100000000倍,结果直接运行不了,运行框都不出来了...⊙﹏⊙b汗附ac代码:#include #include #define MAX 11char a[MAX], b[MAX];int main(){ int t; long long s; scanf("%d", &t); while(t-- && scanf("%s%s", a, b)){ s = 0; int m = strlen(a), n = strlen(b); for(int i = 0; i != m; ++i){ i 阅读全文
posted @ 2014-02-12 20:30 长木Qiu 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题要打表,否则容易超时。附ac代码:#include #include int main(){ int n, m, i, x, y; scanf("%d%d", &n, &m); int *a = (int *)malloc(sizeof(int) * (n + 1)); for(i = 1, a[0] = 0; i <= n; ++i){ scanf("%d", &a[i]); a[i] += a[i - 1]; } while(m-- && scanf("%d%d", &am 阅读全文
posted @ 2014-02-12 18:22 长木Qiu 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题只需要将所有物品按照降序排序,然后从上往下取就行,附ac代码:#include #include struct Node{ int v, w;};int cmp(const void *a, const void *b){ return (*(Node *)b).v - (*(Node *)a).v; //按单位价值降序}int main(){ int t, s, v, w, m; Node a[11], sum; scanf("%d", &t); while(t-- && scanf("%d%d", &s, 阅读全文
posted @ 2014-02-12 17:20 长木Qiu 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题的技巧是:能被3整除的自然数各位的和能被3整除,9也同理。再也不把strlen放进循环里了。这次放进去直接超时了我去。附ac代码:#include #include #define MAX 1000000 + 2char s[MAX];int main(){ int t, sum; scanf("%d", &t); while(t-- && scanf("%s", s)){ sum = 0; int len = strlen(s); for(int i = 0; i != len; ++i) sum += s[i] - 阅读全文
posted @ 2014-02-12 16:28 长木Qiu 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题。解法可参考NYOJ 88附ac代码:#include long long f(int a, int b, int c){ if(a == 1) return 1 % c; if(b == 1) return a % c; long long s = f(a, b / 2, c); s = s * s % c; if(b & 1) return s * a % c; return s;}int main(){ int a, b, c, t; scanf("%d", &t); while(t-- && scanf("%d 阅读全文
posted @ 2014-02-12 15:46 长木Qiu 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题。附ac代码:#include #include int a[100];int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}struct Node{ int a, n;};int main(){ int t, n; Node max; scanf("%d", &t); while(t-- && scanf("%d", &n)){ int i; for(i = 0; i != n; ++i) scanf("%d&qu 阅读全文
posted @ 2014-02-12 15:13 长木Qiu 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 原题链接很经典的一道题。阶乘和有个特点就是前n项和总比第n+1项小,这题就需要这个性质。附ac代码:#include int a[11];int jie(int n){ //计算阶乘 int i, s = 1; for(i = 2; i = a[i]) n -= a[i]; n == 0 ? printf("Yes\n") : printf("No\n"); } return 0;} 阅读全文
posted @ 2014-02-12 14:37 长木Qiu 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 原题链接设金片数量为n时所需要的步骤为F(n),则易得递推式F(n) = 2F(n-1) + 1; 易推得F(n) = 2^n - 1;但是一般的累乘容易超时,这题需要一个时间消耗为O(log n)的算法。附ac代码:#include #define mod 1000000long long power(int n){ //若n为偶数,则n个2相乘,等于前n/2个2相乘的平方 //若n为奇数,则n个2相乘,等于前n/2个2相乘的平方再乘以2 if(n == 1) return 2; long long t = power(n / 2) % mod; t = t * t % mod; if(n 阅读全文
posted @ 2014-02-12 12:45 长木Qiu 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 原题链接由于10可以分解为质因数2 * 5,所以可以将原阶乘分解求出2和5因子的数量,则末尾0的个数就是2和5中数量较少的那个的数量。附ac代码:#include int main(){ int t, n; scanf("%d", &t); while(t-- && scanf("%d", &n)){ int a = 0, b = 0; //分别存储质因子‘2’和、‘5’的数量 int x = n; //副本 while(x) a += (x /= 2); while(n) b += (n /= 5); printf(&q 阅读全文
posted @ 2014-02-12 10:50 长木Qiu 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 原题链接直接应用递推公式打表。附ac代码:#include int main(){ int t, n, a[41] = {0, 0, 1, 2}; for(int i = 4; i != 41; ++i) a[i] = a[i - 1] + a[i - 2]; scanf("%d", &t); while(t-- && scanf("%d", &n)) printf("%d\n", a[n]); return 0;} 阅读全文
posted @ 2014-02-12 01:23 长木Qiu 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题不需要考虑+123 +456的情况,所以就简单了一些。附ac代码:#include #include #define MAX 1000 + 1char a[MAX], b[MAX];int main(){ int x, y; while(scanf("%s%s", a, b) == 2){ if(a[0] == b[0] && a[0] == '0') break; x = strlen(a); y = strlen(b); if(a[0] != '-' && b[0] != '-' 阅读全文
posted @ 2014-02-12 01:08 长木Qiu 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题,只要将乘客体重排序就好办了。附ac代码:#include #include int a[301];int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int t, w, n, x, count; scanf("%d", &t); while(t-- && scanf("%d%d", &w, &n)){ x = n; while(x--) scanf("%d", & 阅读全文
posted @ 2014-02-12 00:38 长木Qiu 阅读(111) 评论(0) 推荐(0) 编辑