hdoj I can do it! 3552 (贪心&模拟)

133 篇文章 0 订阅
27 篇文章 0 订阅

I can do it!

Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1016 Accepted Submission(s): 473


Problem Description
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.

Input
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 A i and B i indicate the Property A and Property B of the ith element. (0 <= A i, B i <= 1000000000)

Output
For each test cases, output the minimum value.

Sample Input
  
  
1 3 1 100 2 100 3 1

Sample Output
  
  
Case 1: 3
//题意: /*有n个元素,每个元素有两个属性(x,y)。现在要将这n个元素分成两个集合(A,B); 分成两个集合后再求出最小的sum的值, 其中sum=(集合A中最大的属性值x)+(集合B中最大的属性值y); */
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct zz
{
	int x;
	int y;
}q[100010];
int cmp(zz a,zz b)
{
	return a.x>b.x;
}
int main()
{
	int t,T=1,n;
	int i,j;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
			scanf("%d%d",&q[i].x,&q[i].y);
		sort(q+1,q+n+1,cmp);
		int ans=0x3f3f3f3f;
		q[n+1].x=0;
		q[0].y=0;
		int B=0;
		for(i=1;i<=n+1;i++)
		{
			B=max(B,q[i-1].y);
			ans=min(ans,q[i].x+B);
		}
		printf("Case %d: %d\n",T++,ans);
	}
	return 0;
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值