【set+贪心】HDU 4268——Alice and Bob
来源:互联网 发布:大数据与银行风险管理 编辑:程序博客网 时间:2024/06/05 01:00
来源:点击打开链接
去年网络赛第一场的第二个题。当时也想到了用贪心,可是超时了,现在复习了起来,发现可以用mutliset,先把alice和bob出的卡片按长度排序,再把所有剩下的矩形队进行贪心,贪当前alice与bob差距最小的矩形队。
用到了upper_bound()参数。
#include <iostream>#include <set>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;multiset<int> tar;multiset<int>::iterator it;class box{public:int length,high;};bool cmp(box a,box b){return a.length<b.length;}box alice[200009],bob[200009];int main(){int testcase;cin>>testcase;for(int t=1;t<=testcase;t++){memset(alice,0,sizeof(alice));memset(bob,0,sizeof(bob));tar.clear();int boxnum;cin>>boxnum;for(int i=0;i<boxnum;i++)cin>>alice[i].length>>alice[i].high;for(int j=0;j<boxnum;j++)cin>>bob[j].length>>bob[j].high;sort(alice,alice+boxnum,cmp);sort(bob,bob+boxnum,cmp);int ans=0;int pos=0;for(int i=0;i<boxnum;i++){while(pos<boxnum && bob[pos].length<=alice[i].length){tar.insert(bob[pos].high);pos++;}it=tar.upper_bound(alice[i].high);if(tar.size()>0 && it!=tar.begin())it--;if(tar.size()>0 && (*it)<=alice[i].high) { ans++; tar.erase(it); } }cout<<ans<<endl;}return 0;}
- 【set+贪心】HDU 4268——Alice and Bob
- hdu 4268 Alice and Bob (set+贪心)
- HDU 4268 Alice and Bob (set+贪心)
- HDU 4268 Alice and Bob 贪心+set应用
- HDU 4268 Alice and Bob——STl upper_bound + 贪心
- hdoj 4268 Alice and Bob 【贪心 + set】
- HDU 4268 Alice and Bob(贪心+数据结构)
- HDU 4268 Alice and Bob(贪心)
- hdu 4268 Alice and Bob(贪心)
- HDU 4268 Alice and Bob(贪心)
- HDU 4268 Alice and Bob (贪心)
- HDU 4268 Alice and Bob(贪心+multiset)
- HDU 4268 Alice and Bob(贪心)
- Alice and Bob(贪心HDU 4268)
- HDU 4268-Alice and Bob-贪心
- hdu 4268 Alice and Bob(贪心)
- HDU 4268 Alice and Bob set用法
- HDU 4268-Alice and Bob( STL: set)
- Ubuntu下为Firefox安装Adobe Flash Player
- iOS多线程GCD
- 60 Commands of Linux : A Guide from Newbies to System Administrator
- 判断一个点是否在多边形内部
- 对 Linux 新手非常有用的20个命令
- 【set+贪心】HDU 4268——Alice and Bob
- android listview重要属性总结
- linux中的lo回环接口
- 利用HTML5将现有网页转成mobile版
- 对中级 Linux 用户非常有用的 20 个命令
- 通过tftp32在3110E上调试程序
- android 知识点大全 面试
- Python邮件客户端编写之wxPython树形控件
- hdu 4323 编辑距离(经典) 动态规划