突击战(Commando War,UVa 11729)
2017-12-27 21:42
393 查看
题目链接
https://vjudge.net/problem/UVA-11729题解
贪心题,将J值大的任务先交代是最优的。所以,只需将任务存放在结构体中,对结构体按J值从大到小排序即可。
代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1e3+100; struct node { int b,j; bool operator<(const node &x)const { return j>x.j; } }a[maxn]; int main() { int N,t=1; while(scanf("%d",&N) && N) { int ans=0,now=0; for(int i=0;i<N;i++) { scanf("%d%d",&a[i].b,&a[i].j); } sort(a,a+N); for(int i=0;i<N;i++) { ans=max(ans,now+a[i].b+a[i].j); now=now+a[i].b; } printf("Case %d: %d\n",t++,ans); } return 0; }
相关文章推荐
- uva 11729 突击战 Commando War 思维
- UVa11729 Commando War(突击战)
- 突击战(Commando War, UVa 11729)
- 突击战(Commando War,UVa 11729 )
- UVa 11729 Commando War 突击战
- (uva 11729)突击战( Commando War)
- 贪心-突击战(Commando War, UVa 11729)
- UVa 11729 Commando War 突击战
- UVa 11729 Commando War 突击战(贪心)
- UVA 11729 Commando War 突击战 【贪心】
- UVA 11292 The dragon of Loowater勇士斗恶龙 11729 突击战 Commando War
- UVa11729 - Commando War (贪心/思维)
- UVa 11729 - Commando War
- uva11729 - Commando War
- UVA 11729 Commando War
- uva 11729 Commando War(贪心算法)
- UVA 11729 - Commando War(贪心)
- Commando War UVA - 11729
- UVA 11729 Commando War
- UVA-11729 - Commando War(贪心、排序)