uva11134 fabled rooks 贪心+问题独立分解
来源:互联网 发布:java 继承多个类 编辑:程序博客网 时间:2024/06/04 20:14
有点不太明白为什么问题是独立的。。
这里这样贪心是因为,越往小的地方走,灵活性越好。。
#include<iostream>#include<bits/stdc++.h>using namespace std;#define sf scanf#define pf printf#define mem(a,b) memset(a,b,sizeof(a));#define inf 0x3f3f3f3f#define INF 1e9;#define LL long long#define bug1 printf("bug1\n");#define bug2 printf("bug2\n");const int maxn=5010;struct Node{ int r,l; int id; bool friend operator <(Node a,Node b){ if(a.l==b.l)return a.r>b.r; return a.l>b.l; }}xx[maxn],yy[maxn];int n;int ans[maxn][2];bool solve(Node *a,int pos){ priority_queue<Node>q; for(int i=1;i<=n;++i){ q.push(a[i]); } int col=1; while(!q.empty()){ Node tmp=q.top();q.pop(); if(tmp.r<col)return false; if(tmp.l<col){ tmp.l=col; q.push(tmp);continue; } ans[tmp.id][pos]=max(tmp.l,col); col=max(tmp.l,col)+1; } return true;}int main(){ while(~sf("%d",&n)){ for(int i=1;i<=n;++i){ sf("%d%d%d%d",&xx[i].l,&yy[i].l,&xx[i].r,&yy[i].r); xx[i].id=yy[i].id=i; } if(solve(xx,0)&&solve(yy,1)){ for(int i=1;i<=n;++i){ pf("%d %d\n",ans[i][0],ans[i][1]); } } else{ pf("IMPOSSIBLE\n"); } }}
0 0
- uva11134 fabled rooks 贪心+问题独立分解
- Uva11134 Fabled Rooks【问题分解+贪心】【例题8-4】
- UVa11134 - Fabled Rooks(贪心)
- UVA11134 Fabled Rooks(贪心)
- UVA11134-Fabled Rooks(贪心)
- 【高效算法设计——问题分解】Uva11134 Fabled Rooks
- Uva11134 Fabled Rooks(贪心,优先级队列)
- UVA11134- Fabled Rooks
- uva11134 -Fabled Rooks
- UVA11134 Fabled Rooks
- Uva 11134 Fabled Rooks (问题分解 + 贪心放置)
- uva11134 Fabled Rocks 贪心
- 解题报告 之 UVA11134 Fabled Rooks
- UVA 11134 - Fabled Rooks(贪心+优先队列)
- UVa 11134 Fabled Rooks(贪心)
- UVA - 11134 Fabled Rooks 优先队列+贪心
- UVa 11134 - Fabled Rooks(贪心)
- uva 11134 - Fabled Rooks 优先队列 + 贪心
- EditText不弹出软键盘
- 如何释放linux cache占用的内存
- Oracle安装后修改用户名和密码
- PAT 乙等 1001 C语言
- Lowest Unique Price (第六届省赛)map
- uva11134 fabled rooks 贪心+问题独立分解
- Android studio在真机上调试程序的步骤
- <mvc:default-servlet-handler/>不拦截静态资源的前提条件
- 基于react实现一个简单的评论框/留言板React-messageboard
- POJ 2576 Tug of War 二维背包 OR 随机化
- 学习淘淘商城第四十一课(使用solrj来测试索引库)
- 连接mysql注意事项:报错access denied for user root...
- 图论-网络流
- 中国经济衰退 周期投资风向标