hdoj 3552 —— 思维题

I can do it!

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


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
 

Author
HyperHexagon
 

Source
 

Recommend
zhengfeng
 
题意是给你n个元素,每个元素有A,B两个属性,你现在要去把这些元素分到X,Y两个集合中,使得X集合中属性A的最大值和集合Y中属性B的最大值之和最小,输出最小值。
思路是从大到小枚举A,因为A值已定,那么属性A的值比A大的元素必然在Y集合中,从而确定bmax,然后枚举ans可解。
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <utility>

using namespace std;
//#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid  , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
//#define mid ((l + r) >> 1)
#define mk make_pair
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
const int MAXN = 100000 + 500;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 1 << 29;
const int IMIN = 0x80000000;
const double e = 2.718281828;
#define eps 1e-8
#define DEBUG 1
#define mod 1000000007
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
typedef pair<int , int> pi;
///#pragma comment(linker, "/STACK:102400000,102400000")__int64 a[10050];
struct Node
{
    int a , b;
}node[MAXN];
bool cmp(const Node & a , const Node & b)
{
    if(a.a != b.a)return a.a < b.a;
    return a.b < b.b;
}
int main()
{
    int n ;
    int t;
    scanf("%d" , &t);
    FORR(kase , 1 , t)
    {
        scanf("%d" , &n);
        FORR(i , 1 , n)
        {
            scanf("%d%d" , &node[i].a , &node[i].b);
        }
        sort(node + 1 , node + n + 1 , cmp);
        int bmax = 0;
//        REPP(i , n - 1, 1)node[i].b = max(node[i].b , node[i + 1].b);
        int ans = node[n].a;
        REPP(i , n , 1)
        {
            bmax = max(bmax , node[i].b);
            ans = min(ans , node[i - 1].a + bmax);
        }
        ans = min(ans , max(node[1].b , bmax));
        printf("Case %d: %d\n" , kase , ans);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值