贪心+优先队列+问题分解

对x,y 分开处理

当 xl<cnt(当前处理行)时,不能简单的选择cnt,而是应该让xl=cnt 并重新加入优先队列。(y的处理同上)

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; struct node {
int l,r;
int id;
friend bool operator < (const node &dis,const node &res){
if (dis.l!=res.l) return dis.l>res.l;
else return dis.r>res.r;
}
}rookx[],rooky[]; int ans[][];
int n; int solved (node* x,int p){
priority_queue<node> q;
while (!q.empty())
q.pop();
for (int i=;i<=n;i++)
q.push(x[i]);
int cnt=;
while (!q.empty() ){
node a;
a=q.top();
q.pop() ;
if (a.r<cnt)
return ;
if (a.l<cnt){
a.l=cnt;
q.push(a);
continue ;
}
if (a.l>cnt){
return ;
}
ans[p][a.id]=cnt++;
}
return ;
} int main (){
while (cin>>n&&n){
for (int i=;i<=n;i++){
cin>>rookx[i].l>>rooky[i].l>>rookx[i].r>>rooky[i].r;
rookx[i].id=rooky[i].id=i;
}
if (solved (rookx,)&&solved (rooky,)){
for (int i=;i<=n;i++)
cout<<ans[][i]<<" "<<ans[][i]<<endl;
}
else cout<<"IMPOSSIBLE"<<endl;
}
return ;
}

UVA 11134 Fabled Rooks的更多相关文章

  1. UVA - 11134 Fabled Rooks[贪心 问题分解]

    UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to t ...

  2. uva 11134 - Fabled Rooks(问题转换+优先队列)

    题目链接:uva 11134 - Fabled Rooks 题目大意:给出n,表示要在n*n的矩阵上放置n个车,并且保证第i辆车在第i个区间上,每个区间给出左上角和右小角的坐标.另要求任意两个车之间不 ...

  3. UVA 11134 Fabled Rooks 贪心

    题目链接:UVA - 11134 题意描述:在一个n*n(1<=n<=5000)的棋盘上放置n个车,每个车都只能在给定的一个矩形里放置,使其n个车两两不在同一行和同一列,判断并给出解决方案 ...

  4. uva 11134 fabled rooks (贪心)——yhx

    We would like to place n rooks, 1 n 5000, on a n nboard subject to the following restrictions• The i ...

  5. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

  6. UVa 11134 - Fabled Rooks 优先队列,贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. UVa 11134 - Fabled Rooks——[问题分解、贪心法]

    We would like to place n rooks, ≤ n ≤ , on a n × n board subject to the following restrictions • The ...

  8. UVa 11134 Fabled Rooks(贪心)

    题目链接  题意  在n*n的棋盘上的n个指定区间上各放1个'车’ , 使他们相互不攻击(不在同行或同列),输出一种可能的方法. 分析 每行每列都必须放车,把行列分开看,若行和列同时有解,则问题有解. ...

  9. UVA 11134 Fabled Rooks(贪心的妙用+memset误用警示)

    题目链接: https://cn.vjudge.net/problem/UVA-11134 /* 问题 输入棋盘的规模和车的数量n(1=<n<=5000),接着输入n辆车的所能在的矩阵的范 ...

随机推荐

  1. css3属性:column分栏

    css3选择器中提出了分栏的属性,其浏览器支持情况为:Internet Explorer 10 和 Opera 支持 column 属性,Firefox 支持替代的 -moz-column 属性,Sa ...

  2. ReferenceError: $ is not defined

    蛋疼的问题,原因是jquery导入顺序不对,任何页面都必须把jquery的导入放在首位,js文件放在其次.

  3. python笔记之常用模块用法分析

    python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...

  4. mvn多模块开发消除重复依赖造成的打包失败

    错误信息: [ERROR] Failed to execute goal on project xiaoyiweifu-core: Could not resolve dependencies for ...

  5. C#基础之------进制转换

    /************************ File:控制台进制类型转换实现 Time:2014年8月12日 Author:小X ****************************/ 代 ...

  6. 在Raspberry上使用小度WIFI

    小度WIFI价格便宜量又足,我一真用它!做个广告先! 它使用联发科MT7601的芯片,质量不错,就是Raspberry下不能直接支持. 首先下载驱动 http://www.mediatek.com/_ ...

  7. vs 2013打开vs 2008解决方案问题解决

    同时安装了vs 2013和vs 2008后,双击vs 2008的解决方案,会出现直接用vs 2013打开的问题. 解决以上问题: 右键选择VS 2008的解决方案,选择开发方式->选择默认程序, ...

  8. eMMC的MMC模式与SPI模式

    MMC存贮卡可以分为MMC和SPI两种工作模式,MMC模式是标准的默认模式,具有MMC的全部特性.而SPI模式则是MMC存贮卡可选的第二种模式,这个模式是MMC协议的一个子集,主要用于只需要小数量的卡 ...

  9. 如何在WPF程序中使用ArcGIS Engine的控件

    原文 http://www.gisall.com/html/47/122747-4038.html WPF(Windows Presentation Foundation)是美国微软公司推出.NET ...

  10. Jquery之家5个顶级Material Design框架

    谷歌Material Design在如今的前端页面设计中非常流行.Material Design的设计风格向我们展示了一个简单而有内涵的现代UI设计方案. Material Design是如此的简洁美 ...