hdu 3552 I can do it! (贪心)

题 目 :

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。问怎样把这些物品分成两个集合(可空),使得 集合A中的max(X)+集合B中的max(Y)  的值最小。

 代 码 :

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<stdio.h>
 4 
 5 using namespace std;
 6 
 7 struct food
 8 {
 9     int x,y;
10 
11 }F[100005];
12 
13 bool com( food a,food b)
14 {
15     return  a.x>b.x ;
16 }
17 
18 int main( ) {
19 
20     int N,n,Min_sum,Max_y,x=0;
21     cin >>N;
22     while( N-- ){
23         cin >>n;
24         for( int i=1;i<=n;i++)
25             scanf("%d %d",&F[i].x,&F[i].y);
26        // if( n==1 ) cout <<"Case " <<++x <<": " <<min(F[1].x,F[1].y) <<endl;
27        //  这句话 要不要都正确 说明 数据中没有这组特殊数据 ;
28        // else {
29             sort(F+1,F+n+1,com);
30             Min_sum=F[1].x; Max_y=F[1].y;
31 
32             for( int i=1;i<=n;i++) {
33 
34                 Min_sum= min( Min_sum, F[i].x+Max_y);  //  感觉像排完序之后 , 用隔板隔开 ,看哪种情况是最优的 。
35                 Max_y= max( Max_y, F[i].y);
36             }
37             cout <<"Case " <<++x <<": " <<Min_sum <<endl;
38        // }
39     }
40     return 0;
41 }
View Code

 

转载于:https://www.cnblogs.com/lysr--tlp/p/rt.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值