uva11134贪心加优先队列
来源:互联网 发布:开挂一样的人生知乎 编辑:程序博客网 时间:2024/06/16 07:06
这个题吧,看着是第一章的,但是也不简单,你要把两个给他分开,横坐标和纵坐标分开计算,然后就是这么回事,然后从区间的左端点开始排序,然后当左端点一样时候,再用右端点进行排序,这个用优先队列进来存。然后就是如果左端点已经小于当前值,那么就需要更新当前左端点,然后加入队列,再来一发。
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int MaxN = 5050;int n;int ans[MaxN][2];struct node{ int r , l , id; friend bool operator<(const node& a , const node& b) { if(a.l != b.l) return a.l > b.l; return a.r > b.r; }}arr1[MaxN],arr2[MaxN];bool check(node* arr1 , int pos){ priority_queue<node>Q; for(int i = 0 ; i < n ; i++) Q.push(arr1[i]); int maxx = 0; while(!Q.empty()){ node tmp = Q.top(); Q.pop(); if(tmp.r < maxx) return false; if(tmp.l < maxx){ tmp.l = maxx; Q.push(tmp); continue; } int cur = max(maxx , tmp.l); ans[tmp.id][pos] = cur; maxx = cur + 1; } return true;}int main(){ while(1){ scanf("%d",&n); if(n == 0) break; for(int i = 0 ; i < n ; i++){ scanf("%d %d %d %d",&arr1[i].l , &arr2[i].l ,&arr1[i].r , &arr2[i].r); arr1[i].id = i , arr2[i].id = i; } if(check(arr1,0)&&check(arr2,1)){ for(int i = 0 ; i < n ; i++){ printf("%d %d\n",ans[i][0],ans[i][1]); } } else printf("IMPOSSIBLE\n"); } return 0;}
0 0
- uva11134贪心加优先队列
- 贪心加优先队列
- Uva11134 Fabled Rooks(贪心,优先级队列)
- uva11134 贪心
- Poj 3253 Fence Repair (贪心加优先队列的应用)
- poj 2431 Expedition (贪心加优先队列)
- poj3614-贪心、优先队列
- EOJ1855 贪心+优先队列
- uvalive4254(贪心+优先队列)
- HOJ1062 贪心+优先队列
- poj3465 贪心+优先队列
- 贪心+优先队列
- 贪心+优先队列
- POJ2010 贪心优先队列
- 贪心+优先队列
- POJ3614Sunscreen(优先队列+贪心)
- 优先队列贪心
- HDU6047优先队列+贪心
- 数据库与表的操作之创建表(CREATE TABLE)
- 数值方法:多项式插值
- odata初探01
- 基于Opencv2.4.11+OpenGL(Qt5.6.0)实现增强现实(一)
- 第五周【项目二-建立链栈算法库】
- uva11134贪心加优先队列
- Codeforces 706C Hard problem
- 27 自定义View 和案例
- Android视频学习(四):网络编程2
- 洛谷 1373
- 中文分词的python实现-基于FMM算法
- 数据库与表的操作之编辑表结构(ALTER TABLE)
- Socket通信c++实现
- POJ2965