UVA 11134 Fabled Rooks
贪心+优先队列+问题分解
对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的更多相关文章
- 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 ...
- uva 11134 - Fabled Rooks(问题转换+优先队列)
题目链接:uva 11134 - Fabled Rooks 题目大意:给出n,表示要在n*n的矩阵上放置n个车,并且保证第i辆车在第i个区间上,每个区间给出左上角和右小角的坐标.另要求任意两个车之间不 ...
- UVA 11134 Fabled Rooks 贪心
题目链接:UVA - 11134 题意描述:在一个n*n(1<=n<=5000)的棋盘上放置n个车,每个车都只能在给定的一个矩形里放置,使其n个车两两不在同一行和同一列,判断并给出解决方案 ...
- 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 ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- UVa 11134 - Fabled Rooks 优先队列,贪心 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11134 - Fabled Rooks——[问题分解、贪心法]
We would like to place n rooks, ≤ n ≤ , on a n × n board subject to the following restrictions • The ...
- UVa 11134 Fabled Rooks(贪心)
题目链接 题意 在n*n的棋盘上的n个指定区间上各放1个'车’ , 使他们相互不攻击(不在同行或同列),输出一种可能的方法. 分析 每行每列都必须放车,把行列分开看,若行和列同时有解,则问题有解. ...
- UVA 11134 Fabled Rooks(贪心的妙用+memset误用警示)
题目链接: https://cn.vjudge.net/problem/UVA-11134 /* 问题 输入棋盘的规模和车的数量n(1=<n<=5000),接着输入n辆车的所能在的矩阵的范 ...
随机推荐
- php error_log 详解
定义和用法 error_log() 函数向服务器错误记录.文件或远程目标发送一个错误. 成功,返回 true,否则返回 false. error_log(error,type,destination, ...
- sql server中主键列的插入问题
仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'dbo.t_test'中的标识列指定显式值. SET IDENTITY_INSERT dbo.t_test ON ,'c' ...
- centos6.4x64安装vncserver
参考文章:http://blog.csdn.net/mchdba/article/details/43058849 主要是远程安装oracle11g需要用到这个东西: 进入系统依次执行下列命令: #查 ...
- shell 脚本文件十六进制转化为ascii码代码
十六进制的A转化为十进制ASCII码: 1 printf "%d\n" "'A" 十六进制的A转化为十六进制ASCII码: 1 printf "%x\ ...
- 监控父元素里面子元素内容变化 DOMSubtreeModified
1监控ul的li的变化情况,并实时输出li的长度 布局: <ul id="isSelected"></ul> <span id="modal ...
- js埋点(转载)
页面埋点的作用,其实就是用于流量分析.而流量的意思,包含了很多:页面浏览数(PV).独立访问者数量(UV).IP.页面停留时间.页面操作时间.页面访问次数.按钮点击次数.文件下载次数等.而流量分析又有 ...
- LR实战之Discuz开源论坛——登录脚本检查点
在开发Discuz登录脚本时,遇到的一个问题是怎么去验证虚拟用户真正的登录成功,当然,熟悉LoadRunner工具的人就会知道,在脚本中使用检查点,对,没错! 我们知道,LR检查点功能有两种:文本检查 ...
- C#实训 打字游戏
StatusStrip控件 状态条 =进度条+标签 等集合体
- android——ObjectAnimator动画(一)
直接贴上集中用法 package com.example.test; import com.example.test.views.CircleView; import android.animatio ...
- net 2.0使用ajax
asp.net ajax中用到了几个dll文件,这些可以从网上下载.http://ajax.asp.net站点下可以找到相关的下载.这其中包括:System.Web.Extensions.dll.Sy ...