HDOJ--3552--I can do it!

该博客介绍了如何解决一个数学问题,即如何将具有两个属性A和B的元素分成两组,使得A组的最大A属性值加上B组的最大B属性值的总和最小。这个问题通过贪心算法进行解决,通过对每个元素的最大属性值进行枚举,确定元素所属的集合,以确保总和最小。博客提供了详细的解题思路和代码实现。
摘要由CSDN通过智能技术生成

题目描述:
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 A i and B i indicate the Property A and Property B of the ith element. (0 <= A i, B i <= 1000000000)
输出描述:
For each test cases, output the minimum value.
输入:
1
3
1 100
2 100
3 1
输出:
Case 1: 3
题意:
一个元素分为2个属性,a和b。然后将元素分成2个集合A和B。求出A集合的a属性的最大值+B集合的b属性的最大值,的最小值
题解
贪心问题
然后枚举max(x),确定A、B集合,并时刻更新B的最大。
对于A而言,当max(x)确定的时候,大于x的放B放,这样才不会使max(x)变大。
代码:

#include<cstdio>
#include<cstring>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值