独木舟上的旅行(贪心)
2011-10-22 14:26
211 查看
/*日期:2011-10-22 作者:xiaosi 题目: 独木舟上的旅行(贪心) */ #include<iostream> #include<cstdio> #include<stdlib.h> using namespace std; int weight[301]; int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } int main() { int N; while(scanf("%d",&N)!=EOF) { while(N--) { int i,j,W,n,count=0,k; scanf("%d %d",&W,&n); for(i=0;i<n;i++) { scanf("%d",&weight[i]); } qsort(weight,n,sizeof(weight[0]),cmp); i=0;k=n-1; while(i<=k) { if(i!=k) { if(weight[i]+weight[k]<=W) { i++; k--; } else { i++; } } else { i++; } count++; } printf("%d\n",count); } } return 0; }
相关文章推荐
- 【南理oj】71 - 独木舟上的旅行(贪心)
- nyoj--71 独木舟上的旅行(贪心)
- NYOJ-独木舟上的旅行(贪心)
- 独木舟上的旅行(贪心)
- NYOJ71——独木舟上的旅行(贪心)
- nyoj 71 独木舟上的旅行 贪心
- 71 独木舟上的旅行【贪心】
- 独木舟上的旅行 贪心 数组
- 贪心——乘船问题——ny_71独木舟上的旅行
- 独木舟上的旅行【贪心】
- 2017.9.9独木舟上的旅行(贪心)
- 独木舟上的旅行(南阳oj71)(贪心)
- nyoj 71 独木舟上的旅行 (贪心)
- nyoj 71 独木舟上的旅行(贪心专题)
- 南阳oj NYOj 贪心 题目71 独木舟上的旅行
- 独木舟旅行(简单贪心)
- nyoj 71 独木舟上的旅行 【贪心&&简单】
- 独木舟上的旅行(贪心)
- NYOJ-71 独木舟上的旅行(贪心)
- NYOJ 71 独木舟上的旅行(贪心)