uva11729 Commando War 水题
刘汝佳《算法竞赛入门经典训练指南 1.1例2
表示uva这么卡,让人怎么受得了。。。
1 ///2014.4.12 2 ///uva11729 3 ///刘汝佳《算法竞赛入门经典训练指南 1.1例2 4 5 #include <iostream> 6 #include <cstdio> 7 #include <string> 8 #include <cmath> 9 #include <algorithm> 10 #include <climits> 11 using namespace std; 12 13 #define maxn 1010 14 int n; 15 struct job{ 16 int b,j; 17 }; 18 job A[maxn]; 19 bool cmp(job A,job B){ 20 return A.j<B.j; 21 } 22 23 int main() 24 { 25 // freopen("in","r",stdin); 26 // freopen("out","w",stdout); 27 int cas = 1; 28 while( cin>>n && n ){ 29 for(int i=0 ; i<n ; i++) 30 cin>>A[i].b>>A[i].j; 31 32 sort(A,A+n,cmp); 33 int ttime = 0; 34 int nowtime = 0; 35 for(int i=n-1 ; i>=0 ; i--){ 36 int a = nowtime + A[i].b+A[i].j; 37 if( a>ttime ) 38 ttime = a; 39 nowtime += A[i].b; 40 } 41 cout<<"Case "<<cas++<<": "<<ttime<<endl; 42 } 43 return 0; 44 }