Hdu 3552 I can do it!(贪心)
来源:互联网 发布:面板数据到底是怎样的 编辑:程序博客网 时间:2024/05/16 16:13
I can do it!
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1060 Accepted Submission(s): 498
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个元素,每个元素有x,y两个属性,让你把这些元素分成两个集合A和B,让A中x属性的最大值和B中y属性的最大值加和最小。可以想到,将n个元素按照x属性的值排序后,如果A集合中x的属性最大值确定的话,那么和它相加的那个值一定是剩下元素中y属性的最大值,因为说白了x属性的最大值就是A和B集合的分界线,A都分出来了那剩下的就是B,所以我们枚举A的x属性最大值就行了#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int maxn = 100005;const int Inf = 0x3f3f3f;int t,n;struct Node{ int x; int y;}node[maxn];int Sort[maxn];int cmp(Node a,Node b){ return a.x < b.x;}int main(){ scanf("%d",&t); int cnt = 0; while(t--) { cnt++; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&node[i].x,&node[i].y); } sort(node,node+n,cmp); int max = -1; int min = Inf; for(int i=n-1;i>=0;i--) { if(max < node[i].y) max = node[i].y; Sort[i] = max; } for(int i=0;i<n-1;i++) { int sum = node[i].x + Sort[i+1]; if(min > sum) min = sum; } printf("Case %d: ",cnt); printf("%d\n",min); }}
0 0
- HDU 3552 I can do it!(贪心)
- Hdu 3552 I can do it!(贪心)
- HDU 3552 I can do it!(贪心)
- HDOJ 3552 I can do it!(贪心)
- hdoj I can do it! 3552 (贪心&模拟)
- HDU 3552 I can do it!
- hdu 3552 I can do it!
- hdu 3552 I can do it! (思维)
- hdoj--3552--I can do it!(贪心模拟)
- hrbust 1079 I can do it(贪心)
- I CAN DO IT
- hdu3552I can do it!(贪心)
- 哈理工oj 1079 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 di it!
- 变化太快,how can I do and change it?
- Ukey,网页,web demo访问U盘用户验证
- BeanFactory or ApplicationContext in Spring
- android&&java 环境变量配置步骤
- USACO Section1.1 TEXT Submitting Solutions
- 全局变量与局部变量的小结
- Hdu 3552 I can do it!(贪心)
- Spring-EL表达式
- 斯坦福大学机器学习笔记(4)-logistic回归
- 简单分析CVE-2015-1805
- 经典面试题:一张表区别DOM解析和SAX解析XML
- leetcode #44 in cpp
- 二叉树的创建和查找指定值路径
- linux 内核与用户空间通信
- Toast Notification