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

对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. 符号三角形(hdu 2510 搜索+打表)

    符号三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. TCLP 第一章 1.5字符输入输出

    #include <stdio.h> /* 将输入复制到输出:版本1 */ int main() { int c; /* 注意是int而不是char,除了存储char类型字符,还要存储EO ...

  3. 电子工程师名片——SPI NOR Flash

    使用了MX25L512的SPI接口的Flash 电路连接图: 总的大小512kb,即64kB,sector的大小为256 Bytes,block的大小为4k Bytes 调试时出现的问题: 1.Fla ...

  4. Qt中事件分发源代码剖析(一共8个步骤,顺序非常清楚:全局的事件过滤器,再传递给目标对象的事件过滤器,最终传递给目标对象)

    Qt中事件分发源代码剖析 Qt中事件传递顺序: 在一个应该程序中,会进入一个事件循环,接受系统产生的事件,并且进行分发,这些都是在exec中进行的.下面举例说明: 1)首先看看下面一段示例代码: in ...

  5. FileStream类

    使用FileStream能够对对系统上的文件进行读.写.打开.关闭等操作.并对其他与文件相关的操作系统提供句柄操作,如管道,标准输入和标准输出.读写操作可以指定为同步或异步操作.FileStream对 ...

  6. 如何清空android ListView控件的内容

    第一种方法: listView.setAdapter(null); 第二种方法: listAdapter.clear(); listAdapter.notifyDataSetChanged() ; 满 ...

  7. Search Insert Position 解答

    Question Given a sorted array and a target value, return the index if the target is found. If not, r ...

  8. LeeCode-Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  9. 关于 MVC 字段 默认值

    以下是网友的疑问: ================================================================ Html.EditorFor(model=> ...

  10. Impala 3、Impala、Hbase整合

    Impala可以通过Hive外部表方式和HBase进行整合,步骤如下: • 步骤1:创建hbase 表,向表中添加数据 create 'test_info', 'info' put 'test_inf ...