I can do it!

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

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
 
Author
HyperHexagon
 

题解:题意好难理解啊,意思是给你一些元素,然后把这些元素分到两个集合里面;

然后找A集合中a最大值加上B集合中b最大值的和的最小化;可以用贪心来找。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define T_T while(T--)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=100010;
struct Node{
int a,b;
friend bool operator < (Node x,Node y){
return x.a>y.a;
}
};
Node dt[MAXN];
int main(){
int T,N,kase=0;
SI(T);
T_T{
SI(N);
for(int i=0;i<N;i++)SI(dt[i].a),SI(dt[i].b);
sort(dt,dt+N);
int A,B=0,ans=INF;
for(int i=0;i<N;i++){
ans=min(ans,B+dt[i].a);
B=max(dt[i].b,B);
}
printf("Case %d: %d\n",++kase,ans);
}
return 0;
}

  

I can do it!(贪心)的更多相关文章

  1. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  2. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  7. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  8. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  9. 【贪心】HDU 1257

    HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...

  10. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

随机推荐

  1. poj2311

    博弈论——sg,mex sg性质:1.在末态的状态点为N态. 2.P态的下一步有一个是N态 3.N态的下一步全部是P态. 当然这是对于单点一个游戏的情形,也相当于NIM只有一堆石子. mex(mini ...

  2. Win8安装ASP.net 4.5(转)

    (原文:http://blog.csdn.net/dingxu_ren/article/details/17607451) 今天在我的电脑上部署Web程序时发现页面打不开,网上搜了下是因为先安装的.n ...

  3. leetcode Container With Most Water python

    class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype ...

  4. ubuntu-10.04的测试环境 安装测试 Coreseek开源中文检索引擎-Sphinx中文版

    主要参考文档:http://www.coreseek.cn/products-install/install_on_bsd_linux/ 一. 32位版本: coreseek安装需要预装的软件: ap ...

  5. python之面向对象那点事

    一.类与对象 1.什么是类?类,顾名思义,就是具体相同属性的同一类事物的统称及抽象.对象,指是就是具体的抽象类的实例 以上的说法是不是看起来有点云里来雾里去呢.没错,专业的解释总是让人难以理解,这就是 ...

  6. 注册表与盘符(转victor888文章 )

    转自: http://blog.csdn.net/loulou_ff/article/details/3769479     写点东西,把这阶段的研究内容记录下来,同时也给研究相关内容的同志提供参考, ...

  7. Select XML Nodes by Name [C#]

    原文 http://www.csharp-examples.net/xml-nodes-by-name/ To find nodes in an XML file you can use XPath ...

  8. VS2010/MFC对话框:一般属性页对话框的创建及显示

    一般属性页对话框的创建及显示 本节将介绍一般属性页对话框的创建和显示. 实际上,一般属性页对话框的创建和显示过程和向导对话框是很类似的.鸡啄米将上一节中的向导对话框进行少量修改,使其成为一般属性页对话 ...

  9. 【解决方法】You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)

    出现场景: 正常调试是没有问题的,但是在Archive的时候,报出了这个错误. 问题详情: (null): URGENT: all bitcode will be dropped because ‘x ...

  10. Flex和Servlet结合上传文件报错(二)

    1.详细报错例如以下 一个表单域 不是一个表单域 java.io.FileNotFoundException: D:\MyEclipse\workspace\FlexFileUpload\Web\up ...