题意:在n*n的棋盘上放n个车,使得任意两个车不相互攻击,且第i个车在一个给定的矩形Ri之内,不相互攻击是指不同行不同列,无解输出IMPOSSIBLE,否则分别输出第1,2,……,n个车的坐标。

分析:行和列是无关的,因此把原题分解成两个一维问题。在区间[1,n]内选择n个不同的整数,使得第i个整数在闭区间[n1i, n2i]内。按r优先排序。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
bool vis[MAXN];
int ans[MAXN][];
int n;
struct Node{
int l, r, id;
Node(){}
bool operator < (const Node& a)const{
return r < a.r;
}
}num1[MAXN], num2[MAXN];
bool judge(Node *num, int x){
memset(vis, false, sizeof vis);
sort(num + , num + n + );
for(int i = ; i <= n; ++i){
bool ok = false;
for(int j = num[i].l; j <= num[i].r; ++j){
if(!vis[j]){
vis[j] = true;
ans[num[i].id][x] = j;
ok = true;
break;
}
}
if(!ok) return false;
}
return true;
}
int main(){
while(scanf("%d", &n) == ){
if(!n) return ;
memset(ans, , sizeof ans);
for(int i = ; i <= n; ++i){
scanf("%d%d%d%d", &num1[i].l, &num2[i].l, &num1[i].r, &num2[i].r);
num1[i].id = num2[i].id = i;
}
if(!judge(num1, )){
printf("IMPOSSIBLE\n");
continue;
}
if(!judge(num2, )){
printf("IMPOSSIBLE\n");
continue;
}
for(int i = ; i <= n; ++i){
printf("%d %d\n", ans[i][], ans[i][]);
}
}
return ;
}

UVA - 11134 Fabled Rooks(传说中的车)(贪心)的更多相关文章

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

    题目:点击打开题目链接 思路:为了满足所有的车不能相互攻击,就要保证所有的车不同行不同列,于是可以发现,行与列是无关的,因此题目可以拆解为两个一维问题,即在区间[1-n]之间选择n个不同的整数,使得第 ...

  2. 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 ...

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

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

  4. UVA 11134 Fabled Rooks 贪心

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

  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 (贪心)——yhx

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

  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. Oracle查看正在执行的存储过程

    正在执行的存储过程 select owner,name from v$db_object_cache where type like '%PROCE%' and locks >0 and pin ...

  2. RabbitMq学习笔记——配置

    1.RabbitMq server官网下载地址:https://www.rabbitmq.com 2.Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安 ...

  3. bzoj 4475: [Jsoi2015]子集选取

    233,扒题解的时候偷瞄到这个题的题解了,,GG 暴力发现是2^(nm),然后就是sb题了 #include <bits/stdc++.h> #define LL long long us ...

  4. 「NOIP2007」树网的核

    传送门 Luogu 解题思路 这里着重介绍 \(O(n^3)\) 的做法,毕竟考场上只有 \(N\le300\) \(Q \omega Q\) 首先我们要知道,对任意一条直径算偏心距都是一样的. 证明 ...

  5. 六种方式实现hibernate查询,及IDE推荐

      这些天过的好乱,也许是因为考完试了,心里有些松懈吧.也许是最近发生的事对我有些触动吧.感觉自己都已经不懂自己了.面对一些人的教导,我很感激.因为很多话都对我有非常大的帮助和启发,也让我除了做技术, ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:为图片添加圆角 (IE8 不支持)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. (译)Calculus on Computational Graphs: Backpropagation

    Posted on August 31, 2015 Introduction Backpropagation is the key algorithm that makes training deep ...

  8. idea跑mapreduce结果为空白文本,idea代码被莫名其妙地改动了

    遇到如题的错误, 一开始查找Step1Main.java的代码错误,尝试关掉分区设置,还是一样. 后来以为是mapper或reducer不执行,网上查找了半天也没有正确原因. 最终,偶然间看到redu ...

  9. css 让多出的文字成省略号...

    一,单行 white-space:nowrap; overflow:hidden;text-overflow: ellipsis; 二,多行 display: -webkit-box; overflo ...

  10. Spring Boot-运行部署

    Main方法 直接运行启动类main方法 遵循应用程序入口点的Java约定的标准方法.我们的main方法SpringApplication通过调用委托给Spring Boot的类run. Spring ...