uva 11729 Commando War
2013-09-10 22:22
309 查看
解题思路:按照 J 从大到小的顺序给各个任务排序,然后依次交代
/////////////////////////////////////////////////////////////////////////// //problem_id: uva 11729 //user_id: SCNU20102200088 /////////////////////////////////////////////////////////////////////////// #include <algorithm> #include <iostream> #include <iterator> #include <iomanip> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cmath> #include <queue> #include <stack> #include <list> #include <set> #include <map> using namespace std; /////////////////////////////////////////////////////////////////////////// #pragma comment(linker,"/STACK:1024000000,1024000000") #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// const double EPS=1e-8; const double PI=acos(-1.0); const int x4[]={-1,0,1,0}; const int y4[]={0,1,0,-1}; const int x8[]={-1,-1,0,1,1,1,0,-1}; const int y8[]={0,1,1,1,0,-1,-1,-1}; /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// typedef long long LL; typedef int T; T max(T a,T b){ return a>b? a:b; } T min(T a,T b){ return a<b? a:b; } T gcd(T a,T b){ return b==0? a:gcd(b,a%b); } T lcm(T a,T b){ return a/gcd(a,b)*b; } /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //Add Code: struct Node{ int B,J; bool operator <(const Node &a) const{ return J>a.J; } }t[1005]; /////////////////////////////////////////////////////////////////////////// int main(){ /////////////////////////////////////////////////////////////////////// //Add Code: int n,i,Case=1; while(scanf("%d",&n)!=EOF){ if(n==0) break; for(i=0;i<n;i++) scanf("%d%d",&t[i].B,&t[i].J); sort(t,t+n); int Max=0,sum=0; for(i=0;i<n;i++){ sum+=t[i].B; if(sum+t[i].J>Max) Max=sum+t[i].J; } printf("Case %d: %d\n",Case++,Max); } /////////////////////////////////////////////////////////////////////// return 0; } /////////////////////////////////////////////////////////////////////////// /* Testcase: Input: 3 2 5 3 2 2 1 3 3 3 4 4 5 5 0 Output: Case 1: 8 Case 2: 15 */ ///////////////////////////////////////////////////////////////////////////
相关文章推荐
- uva - 11729 - Commando War
- UVa 11729 - Commando War(贪心)
- Commando War UVa 11729(贪心)
- UVA - 11729 Commando War (贪心)
- UVa - 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 【贪心】
- Uva-11729-Commando War
- UVa 11729 - Commando War
- UVA 11729 Commando War
- UVA 11729 Commando War
- UVA 11729 - Commando War(贪心 相邻交换法)
- UVa 11729 Commando War 突击战
- uva11729 Commando War 水题
- UVA - 11729 - Commando War
- uva 11729 Commando War(贪心算法)