贪心+容器 hdu4268
Please pay attention that each card can be used only once and the cards cannot be rotated.
For each case, the first line is a number N which means the number of cards that Alice and Bob have respectively. Each of the following N (N <= 100,000) lines contains two integers h (h <= 1,000,000,000) and w (w <= 1,000,000,000) which means the height and width of Alice's card, then the following N lines means that of Bob's.
题义大概就是A有一些卡片,B有一些卡片,A的卡片能覆盖B卡片最多多少张(只有长和宽同时大于等于才行)
#include <bits/stdc++.h>
using namespace std;
#define Maxn 100010
struct Node{
int x,y,id;
};
Node G[Maxn*2];
bool cmp(Node n1,Node n2){
if(n1.x == n2.x && n2.y == n2.y) return n1.id > n2.id;
//这里注意排序方式
if(n1.x != n2.x) return n1.x > n2.x;
return n1.y > n2.y;
}
int main()
{
int N;
cin >> N;
while(N--){
int n,t;
cin >> n;
for(int i = 0; i <(n<<1); i++){
scanf("%d%d",&G[i].x,&G[i].y);
if(i < n){
G[i].id = 1;
}else{
G[i].id = 0;
}
}
sort(G,G+(n<<1),cmp);
multiset<int>s;
int cnt = 0;
for(int i = 0; i < (n<<1); i++){
// 这里用了贪心的方法,因为已经排序了,按照从x从小到大的顺序
// 如果是A,放入容器,如果是B,就从A中找到比B大的中的最小的(贪心)
if(G[i].id){
s.insert(G[i].y);
}else{
multiset<int>::iterator it = s.lower_bound(G[i].y);
if(it == s.end() || *it < G[i].y){
// 这步判断很重要
continue;
}else{
cnt++;
s.erase(it);
// 找到就删掉,以后都不再用了
}
}
}
printf("%d\n",cnt);
}
}
贪心+容器 hdu4268的更多相关文章
- hdu4864 hdu4268 贪心 lower_bound
hdu4864 题意: 有n个机器,m个任务,n,m<=100000,每个机器都有工作时间的最大限制xi(0<xi<1440)和完成的最大难度yi(0<=yi<=100) ...
- 【LeetCode】盛最多水的容器【双指针+贪心 寻找最大面积】
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- HDU4268 Alice and Bob(贪心+multiset)
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
- hdu4268贪心
题意: 两个人有一些图片,矩形的,问a最多能够覆盖b多少张图片.. 思路: 明显是贪心,但是有一点很疑惑,如果以别人为主,每次都用自己最小的切能覆盖敌人的方法就wa,而以自己为 ...
- Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- HDU4268 Alice and Bob 【贪心】
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- STL容器的本质
http://blog.sina.com.cn/s/blog_4d3a41f40100eof0.html 最近在学习unordered_map里面的散列函数和相等函数怎么写.学习过程中看到了一个好帖子 ...
- LeetCode(11):盛最多水的容器
Medium! 题目描述: 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, ...
- 【NOI2015】荷马史诗[Huffman树+贪心]
#130. [NOI2015]荷马史诗 统计 描述 提交 自定义测试 追逐影子的人,自己就是影子. ——荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读 ...
随机推荐
- 【感悟】看Hyouka的感想 (1)
最近偶然从B站看到了<冰菓>这个(个人觉得是推理)番 我突然觉得自己曾经做的一些行为欠妥 有才能者的不自知,是对无才能者的讽刺 举个例子就是:即当别人说你很牛的时候,你却说你只 ...
- windows下node.js+sublime中安装coffeescript
node.js中安装Coffeescript 1.我的node.js安装目录 2.node.js 全局模块所在目录 3.node.js安装coffeescript npm install -g c ...
- Android开源项目(转载)
第一部分 界面 ImageView.ProgressBar及其他如Dialog.Toast.EditText.TableView.Activity Animation等等. 一.ListView an ...
- 用Python实现的一个简单的爬取省市乡镇的行政区划信息的脚本
# coding=utf-8 # Creeper import os import bs4 import time import MySQLdb import urllib2 import datet ...
- gnuplot使用
直接用yum安装gnuplot即可,例如 sudo sh -c "yum install gnuplot.x86_64 " 安装以后就可以使用了 编写gnuplot脚本 # grp ...
- URL encode 与 URL decode 的C语言实现
转载自:http://blog.csdn.net/langeldep/article/details/6264058 本文代码为从PHP代码中修改而来,只保留了2个函数. int php_url_de ...
- 不支持关键字: “userid”。
运行程序提示:不支持关键字: “userid”. 找了很久在一篇博客里面提示web.config数据库字符串链接出错.
- LightOj_1284 Lights inside 3D Grid
题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1) 再选择一个点(x2, y2, ...
- OpenJudge_cdqz 数据结构版块小结
题目整理 Challenge 0 随机线性存储表-easy Challenge 1 链表数组-easy Challenge 2 可持久化Treap的可持久化运用-hard Challenge 3 ...
- [BZOJ 3942] [Usaco2015 Feb] Censoring 【KMP】
题目链接:BZOJ - 3942 题目分析 我们发现,删掉一段 T 之后,被删除的部分前面的一段可能和后面的一段连接起来出现新的 T . 所以我们删掉一段 T 之后应该接着被删除的位置之前的继续向后匹 ...