题目地址: 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. Ftp连接错误

    FTP连接上传 文件报错  windows无法访问此文件夹.请确保输入的文件名是否正确,并且您有权访问此文件.. 解决办法 : IE设置为脱机使用,文件浏览器登录ftp时调用IE浏览器,所以无法连接, ...

  2. 使vim中Syntastic支持C++11

    安装好Syntastic后发现不支持c++11,会提示错误incompatible with c++98,解决方法如下: .vimrc中加入: let g:syntastic_cpp_compiler ...

  3. java并发编程_建立概念

    在学习多线程编程时,相信大家会遇到好多概念类的东西,对于这些概念的不准确理解会导致后面越学越糊涂,现将学习过程中遇到的概念整理到这篇博客上,一来记录学习点滴,二来也加深理解,如果有理解不准确的地方,希 ...

  4. ida idc函数列表全集

    下面是函数描述信息中的约定: 'ea' 线性地址 'success' 0表示函数失败:反之为1 'void'表示函数返回的是没有意义的值(总是0) AddBptEx AddBpt AddCodeXre ...

  5. JNI学习&使用过程中的错误

    Part 1 Ubuntu下JNI的简单使用: http://blog.csdn.net/fengqiaoyebo2008/article/details/6210499 Part 2 在eclips ...

  6. win7系统64位"禁用驱动程序签名强制"如何设置?

    换了Win7系统64位旗舰版的朋友是不是都发现了一点,以前32位Win7系统用的好好的小程序小应用,一下子就装不上了.这是由于Win7系统64位系统对于未有认证签名的驱动程序进行了限制安装,而大部分小 ...

  7. Corrupted MAC on input

    Corrupted MAC on input Incorrect MAC received on packet

  8. Web开发之RSET API

    REST介绍 如果要说什么是REST的话,那最好先从Web(万维网)说起. 什么是Web呢?读者可以查看维基百科的词条(http://zh.wikipedia.org/zh-cn/Web),具体的我就 ...

  9. [IOS]包含增删改查移动的tableView展示+plist文件保存+程序意外退出保存Demo

    做一个tableView,包含增删改移动功能,并且修改值的时候,在按home键的时候会自动保存.如果可以的话使者保存自定义的类数组保存到plist中. 实现步骤: 1.创建一个SingleViewAp ...

  10. phpStorm 各种快捷键

    1. ctrl + shift + n: 打开工程中的文件(类似于eclipse中的ctrl+shift+R),目的是打开当前工程下任意目录的文件. 2. ctrl + j: 输出模板 3. ctrl ...