UVa-11729-突击战

题目链接:点击打开链接

突击战其实很简单,就是先把执行时间大的往前排然后依次交待,然后如图比较就可以.

# include <iostream>
# include <numeric>
# include <algorithm>
# include <functional>
# include <list>
# include <map>
# include <set>
# include <stack>
# include <deque>
# include <queue>
# include <vector>
# include <ctime>
# include <cstdlib>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>

using namespace std;

struct node
{
	int t1, t2;
};

int cmp(const struct node s1, const struct node s2)
{
	return s1.t2 > s2.t2;
}


int main(int argc, char *argv[])
{
	int n;
	int flag = 0;
	while(cin >> n && n != 0)
	{
		
		flag++;
		node s[1005];
		for(int i = 0; i < n; i++)
		{
			cin >> s[i].t1 >> s[i].t2;
		}
		sort(s, s + n, cmp);
		// b[x] + b[y] + j[y] 和 b[y] + b[x] + j[x]相比较
		

		int ans = 0, sum = 0;
		for(int i = 0; i < n; i++)
		{
			//sum 表示的是交代时间的时间,然后把执行时间加上然后比较最大值就可以求出来最短的时间
			sum += s[i].t1; //把起始时间加进去
			// b[x] + b[y] + j[y] 和 b[y] + b[x] + j[x]相比较
	//		cout << "t1 = " << s[i].t1 << " t2 = "  << s[i].t2 << " sum = " << sum << " ans = " << ans << " sum + s[i].t2 = " << sum + s[i].t2 << endl;
			ans = max(ans, sum + s[i].t2); // 更新任务时间,求得最小值
		}
		cout << "Case "<<flag << ": " << ans << endl;

	} 
    return 0;
}

猜你喜欢

转载自blog.csdn.net/i_o_fly/article/details/80948860