上一页 1 2 3 4 5 6 7 ··· 17 下一页
  2014年3月15日
摘要: 原题链接郁闷,WA了3次,好在最终找到了原因,qsort的cmp函数有问题,对于浮点数,比较的时候一定要注意。#include #include struct Node{ int x, y; double rate;};int cmp(const void *a, const void *b){ if ((*(Node *)b).rate - (*(Node *)a).rate 0 && i < n; ++i){ if(a[i].y <= m){ s += a[i].x; m -= a[i].y; }else{ s += m * a[i].rate; brea... 阅读全文
posted @ 2014-03-15 01:20 长木Qiu 阅读(135) 评论(0) 推荐(0) 编辑
  2014年3月14日
摘要: 原题链接思路:将每个区间段按照右端点从小到大排序,count赋值为n,从第一个开始以右端点为基准判断是否在接下来的区段中间,若在则--count。#include #include struct Node{ int x, y;};Node arr[101];int cmp(const void *a, const void *b){ return (*(Node *)a).y - (*(Node *)b).y;}int main(){ int n, i, j, count; while(scanf("%d", &n) == 1){ for(i = 0; i != n 阅读全文
posted @ 2014-03-14 23:46 长木Qiu 阅读(119) 评论(0) 推荐(0) 编辑
  2014年3月13日
摘要: 原题链接主要思路:从左到右,逐个比较,若有不同,标记此不同地点,并向右搜寻首个相同点,从该点开始挨个与左边位置交换并统计交换次数。#include #include #define MAX 5000 + 2char str[MAX], str2[MAX];int find(int i){ int j = i, count = 0; char t; while(str[j] != str2[i]) ++j; while(j > i){ t = str[j]; str[j] = str[j - 1]; str[j - 1] = t; --j; ++count; } return cou... 阅读全文
posted @ 2014-03-13 20:57 长木Qiu 阅读(105) 评论(0) 推荐(0) 编辑
  2014年3月12日
摘要: 原题链接思路:首先将最慢的两个弄过去。两种方案:1、A1带A2过去,A1回来,An带An-1过去,A2回来。用时T=A1+An+2*A2;2、A1带An过去,A1回来,A1带An-1过去,A1回来。用时T=An+An-1+2*A1;采用两者中用时较少的方案#include #include int a[1001];int min(int n){ int t1 = a[1] + a[n] + 2 * a[2], t2 = a[n] + a[n - 1] + 2 * a[1]; if(t1 <= t2) return t1; return t2;}int cmp(const void *a, 阅读全文
posted @ 2014-03-12 16:36 长木Qiu 阅读(121) 评论(0) 推荐(0) 编辑
  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) 编辑
上一页 1 2 3 4 5 6 7 ··· 17 下一页