题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4268

贪心思想,用set实现平衡树,但是set有唯一性,所以要用 multiset

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef long long LL;
const int N=100005;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); struct xh
{
LL x,y;
int t;
}a[N<<1]; LL get_ll()
{
LL sum=0;
char c;
while((c=getchar())>'9'||c<'0')
;
sum=c-'0';
while((c=getchar())<='9'&&c>='0')
sum=sum*10+c-'0';
return sum;
} bool cmp(xh a,xh b)
{
if(a.x!=b.x)
return a.x<b.x;
if(a.y!=b.y)
return a.y<b.y;
return a.t<b.t;
} int main()
{
int i,j,T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
a[i].x=get_ll();
a[i].y=get_ll();
a[i].t=1;
}
for(i=n;i<2*n;i++)
{
a[i].x=get_ll();
a[i].y=get_ll();
a[i].t=0;
}
sort(a,a+2*n,cmp);
multiset<int> se;
se.clear();
int cnt=0;
i=j=0;
for(i=0;i<2*n;i++)
{
if(a[i].t==0)
se.insert(a[i].y);
else
{
if(!se.empty())
{
if(a[i].y<*se.begin()) continue;
multiset<int>::iterator it;
it=se.upper_bound(a[i].y);
it--;
cnt++;
se.erase(it); }
}
}
printf("%d\n",cnt);
}
return 0;
}

HDU 4268 Alice and Bob set用法的更多相关文章

  1. hdu 4268 Alice and Bob

    Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  2. hdu 4268 Alice and Bob(multiset|段树)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. HDU 4268 Alice and Bob 贪心STL O(nlogn)

    B - Alice and Bob Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  4. HDU 4268 Alice and Bob(贪心+Multiset的应用)

     题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...

  5. hdu 4268 Alice and Bob(贪心+multiset)

    题意:卡牌覆盖,每张卡牌有高(height)和宽(width).求alice的卡牌最多可以覆盖多少bob的卡牌 思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖. #include<ios ...

  6. hdu 4111 Alice and Bob 记忆化搜索 博弈论

    Alice and Bob Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  7. hdu 3660 Alice and Bob's Trip(树形DP)

    Alice and Bob's Trip Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. HDU 5054 Alice and Bob(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5054 Problem Description Bob and Alice got separated ...

  9. hdu 4111 Alice and Bob(中档博弈题)

    copy VS study 1.每堆部是1的时候,是3的倍数时输否则赢: 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢: 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶 ...

随机推荐

  1. gdb调试整理

    调试环境:linux调试工具:gdb 调试类别 1.调试core文件  gdb 应用程序名 core文件名2.调试正在执行的程序 gdb 应用程序名 pid 3.gdb 应用程序名         4 ...

  2. Linux下关闭node应用

    今天在折腾用node接入微信公众号时,碰到了node应用启动后卡死退出,需要找出该进程关闭的问题,由于对shell脚本不是很熟悉,记录如下: 我们在用npm start启动应用后,通常要关闭时,ctr ...

  3. 如何用VS2010打开VS2012编辑的项目

    找到打开项目的开始图标:,右键点击,选择有文本编辑器打开,用下面的语句将文件里面的前两句替换掉.​Microsoft Visual Studio Solution File, Format Versi ...

  4. 必须用C模拟OS?

    ASM基本必要,至于高级语言就很难说了.去osdev wiki上一翻一堆各种语言实现的玩意. 一个模拟OS其实不太容易完整搭出来,反倒是直接构造内核的后顾之忧少(如果还有真的想在SIGALRM里耍什么 ...

  5. leetcode_question_112 Path Sum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  6. How to run Tomcat without root privileges? 常规用户使用tomcat的80端口

    How to run Tomcat without root privileges? 1. The best way is to use jsvc, available as part of the  ...

  7. BZOJ2697: 特技飞行

    2697: 特技飞行 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 607  Solved: 363[Submit][Status] Descript ...

  8. 【转】Install SmartGit via PPA in Ubuntu 13.10/13.04/12.04/Linux Mint

    原文网址:http://ubuntuhandbook.org/index.php/2013/09/install-smartgit-via-ppa-ubuntu-linux-mint/ This tu ...

  9. Delphi TcxTreelist 设置scrollbars 不起作用的原因

    最近设置TcxTreelist的滚动条,发现水平的不起作用, 即使设置 sboth也不起作用. 查找,发现设置的一些属性导致了这个原因, 建立备忘,如下图: 1.属性, 这个页面,设置的表格,怎么也看 ...

  10. SIP学习之网络链接

    风清扬的CSDN博客  文章分类SIP http://blog.csdn.net/ppy521/article/category/1227390