poj 3190 Stall Reservations1
来源:互联网 发布:软件企业资质证书 编辑:程序博客网 时间:2024/06/10 17:30
堆 + 贪心
难得的好题,自己确实没想到,看了下别人的想法。.
http://www.acjoke.com/?p=164 这个链接的证明比较给力
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<stack>#include<algorithm>using namespace std;const int maxn = 50050;struct Line{ int l,r,index; Line(const int& l = 0,const int& r = 0,const int&index = 0):l(l),r(r),index(index){} Line(const Line& rsh) { l = rsh.l; r = rsh.r; index = rsh.index; } bool operator < (const Line& rsh) const { return l < rsh.l; }};struct Heap{ int id; int fin; Heap(const int& id = 0 ,const int& fin = 0):id(id),fin(fin){} Heap(const Heap& rsh) { id = rsh.id; fin = rsh.fin; } bool operator < (const Heap& rsh) const { return fin > rsh.fin; }};int result[maxn];vector<Line> lines;priority_queue<Heap> heaps;void put_cow( int i,bool flag){ Heap heap; if(flag) { heap.id = heaps.size() + 1; } else { heap.id = heaps.top().id; heaps.pop(); } heap.fin = lines[i].r; result[lines[i].index] = heap.id; heaps.push(heap);}int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL int n; scanf("%d",&n); int l,r; for(int i = 0 ; i < n ; i ++) { scanf("%d %d",&l,&r); lines.push_back(Line(l,r,i)); } sort(lines.begin(),lines.end()); put_cow(0,true); for(int i = 1 ; i < n ; i++) { put_cow(i,lines[i].l <= heaps.top().fin); } printf("%d\n",heaps.size()); for(int i = 0 ; i < n ; i++) { printf("%d\n",result[i]); } return 0;}
0 0
- poj 3190 Stall Reservations1
- poj 3190 Stall Reservations
- POJ-3190-Stall Reservations
- POJ-3190-Stall Reservations
- POJ 3190 Stall Reservations
- POJ-3190-Stall Reservations
- poj 3190Stall Reservations
- poj 3190 Stall Reservations
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- poj-3190-Stall Reservation
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- MFC 学习之 界面美化<1>
- 简单数据持久化/NSUserDefaults(单例) 登陆界面简单验证
- App界面设计:发现闪屏之美
- 1212
- C++名称查找与ADL
- poj 3190 Stall Reservations1
- 从头认识C—break和continue语句
- 数字图像处理之作业2
- Android 高仿微信6.0主界面 带你玩转切换图标变色
- HDU5090 Game with Pearls(贪心)
- JAVA基础---1
- Kettle 增量更新设计技巧
- PAT Advanced Level (1081~1087)
- Hadoop学习笔记(1)安装配置与运行