http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1198&& I can do it!

问题描述
Given n elements, which have two properties, say Property A and Property B. For convenience, we use two integers A i and B i to measure the two properties.
Your task is, to partition the element into two sets, say Set A and Set B , which minimizes the value of max (x∈Set A) {A x }+max (y∈Set B) {B y }.
See sample test cases for further details.
输入
There are multiple test cases, the first line of input contains an integer denoting the number of test cases.
For each test case, the first line contains an integer N, indicates the number of elements. (1 <= N <= 100000)
For the next N lines, every line contains two integers Ai and Bi indicate the Property A and Property B of the ith element. (0 <= Ai, Bi <= 1000000000)
输出
For each test cases, output the minimum value.
样例输入
1
3
1 100
2 100
3 1
样例输出
Case 1: 3
题意:找出一个最大的和最小,
思路:先排序,然后枚举即可,,
AC代码:
 
#include<iostream>
#include<string.h>
#include<cstdio>
#include<memory.h>
#include<algorithm>
#include<vector>
#define N 100005
using namespace std;
typedef struct node
{
	__int64 x;
	__int64 y;
}Node;
Node s1[N];
bool cmp2(Node xx,Node yy)
{
	return xx.y>yy.y;
}
int main()
{
	int T;
	scanf("%d",&T);
	for(int k=1;k<=T;++k)
	{
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;++i)
		scanf("%I64d%I64d",&s1[i].x,&s1[i].y);		
			  sort(s1,s1+n,cmp2);
			  __int64 minx=s1[0].y;
			  __int64 p=-1;
			  for(int i=1;i<n;++i)
			    {
					if(s1[i-1].x>p) p=s1[i-1].x;
					s1[i].y+=p;
			       if(s1[i].y<minx) minx=s1[i].y;
				}printf("Case %d: %I64d\n",k,minx);
	}return 0;
}
基本信息
#:  7214 
题目:  1198 
提交人:  pursuit 
语言:  G++ 
提交时间  2012-07-14 09:34:28 
 



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值