zoukankan      html  css  js  c++  java
  • 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 Ai and Bi 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) {Ax}+max(y∈Set B) {By}.
    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 Ai and Bi indicate the Property A and Property B of the ith element. (0 <= Ai, Bi <= 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
    View Code
    /*
    题目大意:一个元素分为2个属性,a和b。然后将元素分成2个集合A和B。求出A集合的a属性的最大值+B集合的b属性的最大值,的最小值 
    解题思路:一篇很详细的结题报告
    http://blog.csdn.net/dgq8211/article/details/7748078 
    */
    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct Set
    {
        int a, b;
    }SS[100002];
    int cmp(Set x, Set y)
    {
        return x.a>y.a;
    }
    int main()
    {
        int T, n, k=0, i;
        scanf("%d", &T);
        while(T--)
        {
            k++;
            scanf("%d", &n);
            for(i=0; i<n; i++)
            {
                scanf("%d%d", &SS[i].a, &SS[i].b);
            }
            sort(SS, SS+n, cmp);
            int maxsum=SS[0].a, maxb=SS[0].b;
            for(i=1; i<n; i++)
            {
                maxsum=min(maxsum, SS[i].a+maxb);
                maxb=max(maxb, SS[i].b);
            }
            printf("Case %d: %d\n", k, maxsum);
        }
        return 0;
    }
  • 相关阅读:
    你要的SSM(Spring+Springmvc+Mybatis)小项目来了!!!
    王爽《汇编语言》(第三版)实验10解析
    java1.8安装及环境变量配置
    王爽《汇编语言》(第三版)实验9解析
    王爽《汇编语言》(第三版)实验8解析(超详细)
    2020软件工程作业06
    鸽子开发组——冲刺日志(第四天)
    String 类中常用方法
    mysql
    array_merge和加号+的区别
  • 原文地址:https://www.cnblogs.com/Hilda/p/2941587.html
Copyright © 2011-2022 走看看