(UVA step1.2)UVA 11729 Commando War(单独交代+并行执行的最短时间求法)

/*
 * uva_11729.cpp
 *
 *  Created on: 2013年11月17日
 *      Author: Administrator
 */


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>


using namespace std;


struct Job{
	int b,j;

	bool operator<(const Job& b)const{//执行时间长的优先交代
		return j > b.j;
	}
};


int main(){
	int n;
	int counter = 1;
	while(scanf("%d",&n)!=EOF,n){
		int i;
		vector<Job> v;
		int b,j;
		for(i = 0 ; i < n ; ++i){
			scanf("%d%d",&b,&j);
			v.push_back((Job){b,j});//**注意这种写法
		}

		sort(v.begin(),v.end());//**动态数组的排序

		int s = 0;
		int ans = 0;
		for(i = 0 ; i < n ; ++i){
			s += v[i].b;
			ans = max(ans,s + v[i].j);//更新执行完任务的最晚时间
		}

		printf("Case %d: %d\n",counter++,ans);
	}

	return 0;
}

你可能感兴趣的:((UVA step1.2)UVA 11729 Commando War(单独交代+并行执行的最短时间求法))