NYOJ 71 独木舟上的旅行
2014-02-12 00:38
246 查看
原题链接
简单题,只要将乘客体重排序就好办了。
附ac代码:
简单题,只要将乘客体重排序就好办了。
附ac代码:
#include <stdio.h> #include <stdlib.h> 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", &a[x]); qsort(a, n, sizeof(int), cmp); count = n; int i = 0, j = n - 1; while(i < j){ if(a[i] + a[j] <= w) --count, ++i, --j; else --j; } printf("%d\n", count); } return 0; }
相关文章推荐
- 贪心——NYOJ 题目71 独木舟上的旅行
- NYOJ,71,独木舟上的旅行
- NYOJ71-独木舟上的旅行
- NYOJ 71 独木舟上的旅行
- NYOJ 71 独木舟上的旅行
- nyoj 71 独木舟上的旅行
- nyoj 71 独木舟上的旅行(贪心专题)
- nyoj-71-独木舟上的旅行
- nyoj 71 独木舟上的旅行
- Nyoj 71 独木舟上的旅行
- NYOJ 71 独木舟上的旅行(贪心)
- NYOJ题目71-独木舟上的旅行(贪心)
- NYOJ 71 独木舟上的旅行 (贪心)
- NYOJ71独木舟上的旅行
- NYOJ71 独木舟上的旅行
- nyoj 71 独木舟上的旅行
- NYOJ-71 独木舟上的旅行(贪心)
- NYOJ 题目71 独木舟上的旅行
- NYOJ71独木舟上的旅行
- nyoj 71 独木舟上的旅行【贪心】