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. USACO Section 4.3 Street Race(图的连通性+枚举)

    虽说是IOI'95,但是也是挺水的..for 第一问,n最大为50,所以可以直接枚举起点和终点之外的所有点,然后dfs判断是否连通:for 第二问,易知答案一定是第一问的子集,所以从第一问中的答案中枚 ...

  2. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined

    spring-session 集成redis,web.xml配置filter时候出现  No bean named 'springSessionRepositoryFilter' is defined ...

  3. c++读取文件内容并保存到二维数组

    每行数据最后需要Tab处理 #include <iostream> #include <fstream> #include <string> using names ...

  4. 为什么Java项目前会出现一个红色感叹号!

    先看看问题,如下图所示: 造成这个问题的原因是,我把一个 jar 包删除了,然后又配了个新的进去,然后就一直有这个错误,刚开始很郁闷,怎么已经配置过儿,还出现这个问题?关键是代码里面没有报错的.郁闷的 ...

  5. python使用mysql的三个模块:mysql.connector、sqlalchemy、MySQLdb

    在python中使用mysql其实很简单,只要先安装对应的模块即可,那么对应的模块都有什么?官方也没指定也没提供,pcat就推荐自己遇到的3个模块:mysql.connector.sqlalchemy ...

  6. [LeetCode]题解(python):143-Reorder List

    题目来源: https://leetcode.com/problems/reorder-list/ 题意分析: 给定一个链表L:L0→L1→…→Ln-1→Ln,改变链表的排序为: L0→Ln→L1→L ...

  7. 《Pointers On C》读书笔记(第三章 数据)

    1.在C语言中,仅有4种基本数据类型:整型.浮点型.指针和聚合类型(如数组和结构等). 整型家族包括字符.短整型.整型和长整型,它们都分为有符号和无符号两种. 标准规定整型值相互之间大小的规则:长整型 ...

  8. cocos2dx CCControlSlider

    有的同学建议先上图,好吧,先上效果图 再看代码,创建了两个CCControlSlider在主窗口中 // on "init" you need to initialize your ...

  9. Please ensure that adb is correctly located at '...adb.exe' and can be executed.

    Android Launch! The connection to adb is down, and a severe error has occured. You must restart adb ...

  10. nodejs - json序列化&反序列化示例

    // demo-json.js var obj = { "name": "LiLi", "age": 22, "sex" ...