HDOJ--3552--I can do it!(思维)
来源:互联网 发布:新疆人 知乎 编辑:程序博客网 时间:2024/04/30 02:15
I can do it!
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1038 Accepted Submission(s): 482
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.
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)
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
131 1002 1003 1
Sample Output
Case 1: 3
题意:题目的大概意思是,给你N个元素,每个元素里面包括两条性质A,B,你需要把这N个元素分成两个集合A,B。对于这两个集合,选出A集合中最大的,和B集合中最大的.并求出最终MAXA+MAXB的最小值。
难点:1.就是题目的理解。2,,不能用普通的枚举方法,不然会超时,需要想出来一种比较巧妙的枚举方法。
思路:由题意可知,集合A 和集合B 有多种可能 所以需要 一一枚举,每次枚举出A集合中的最大值max,然后比这个最大值MAX还要大的肯定不是集合A中的元素。从而找到集合B ,不断更新min值就好。
ac代码:
#include<stdio.h>#include<string.h>#include<algorithm>#define INF 0x3f3f3f3f#define MAX 100000+10using namespace std;struct pro{int a,b;}num[MAX];bool cmp(pro x,pro y){return x.a>y.a;}int main(){int T,i;scanf("%d",&T);for(i=1;i<=T;i++){int n;scanf("%d",&n);for(int j=1;j<=n;j++)scanf("%d%d",&num[j].a,&num[j].b);sort(num+1,num+n+1,cmp);int B=0,mincost=INF;for(int j=2;j<=n;j++){B=max(B,num[j-1].b);mincost=min(mincost,num[j].a+B);}printf("Case %d: %d\n",i,mincost);}return 0;}
0 0
- hdoj 3552 I can do it! 【思维】
- HDOJ--3552--I can do it!(思维)
- HDOJ 3552 I can do it!
- HDOJ 3552 I can do it!(贪心)
- hdu 3552 I can do it! (思维)
- hdoj I can do it! 3552 (贪心&模拟)
- hdoj--3552--I can do it!(贪心模拟)
- I CAN DO IT
- HDU 3552 I can do it!(贪心)
- Hdu 3552 I can do it!(贪心)
- HDU 3552 I can do it!(贪心)
- HDU 3552 I can do it!
- hdu 3552 I can do it!
- hrbust 1079 I can do it(贪心)
- 变化太快,how can I do and change it?
- 哈理工oj 1079 I can do it【贪心】
- hdu3552I can do it!(贪心)
- can you do it
- pydev的注释快捷键
- centos7 yum install nginx
- 工作流
- 小心使用ArrayList和LinkedList
- Centos7 x64 javaWeb环境搭建
- HDOJ--3552--I can do it!(思维)
- linux-->touch命令详解
- UITableView回调函数的执行顺序
- 使用xib给label等文字显示控件添加attributed属性
- 单例模式(singleton模式)总结
- 求解二进制中1的个数
- 在图片上面添加一个图片,实现12306验证码的选择并获取相关坐标的功能
- Android-socket-client客户端<2>
- 深入分析JavaWeb Item31 -- JDBC(MySQL)事务管理