【例题 8-4 UVA - 11134】Fabled Rooks
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
显然把问题分解成两个子问题。
x轴和y轴分别做。
即n个点要求第i个点在[li,ri]范围内。(ri按左端点、右端点排。尽量取左边的方法是错的。
hack数据:(1,1),(1,3),(2,2)
在安排idx=2的时候,优先用了(1,3)这个区间。导致原本3可以放的。现在放不了了。
所以我们的方法就是。
对于第i个点。
找一个能包含它。
但是右端点又尽量小的区间。
这样,能保证这个选取的区间尽量不影响到后面的点的选取。
(而前面的点无所谓,因为已经安排完了
O(N^2)的复杂度找这样的区间就可以了。
如果数据大的话。
可以考虑用set来处理:比如区间[li,ri]
则可以在li的位置插入一个数据ri
当ri<idx的时候,则在set中把ri去掉。
否则每次都找set中最小的ri.把它删掉。
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
vector < pair<int,pair<int,int> > > v1,v2;
int n;
int x[N+10],y[N+10];
bool ok(vector<pair<int,pair<int,int> > > v,int ju){
for (int i = 1;i <= n;i++){
int mi = 100000;
__typeof v.begin() idx;
for (auto j = v.begin();j!=v.end();j++){
auto temp = *j;
if (temp.first<=i && i<=temp.second.first){
if (temp.second.first<mi){
mi = temp.second.first;
idx = j;
}
}
}
if (mi==100000) return false;
if (ju==0){
x[(*idx).second.second] = i;
}else{
y[(*idx).second.second] = i;
}
v.erase(idx);
}
return true;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
while (cin >>n && n){
v1.clear(),v2.clear();
for (int i = 1;i <= n;i++){
int xl,yl,xr,yr;
cin >> xl >> yl >> xr >> yr;
v1.push_back({xl,{xr,i}});
v2.push_back({yl,{yr,i}});
}
if (ok(v1,0)&&ok(v2,1)){
for (int i = 1;i <= n;i++)
cout << x[i] <<' '<<y[i]<<endl;
}else{
cout <<"IMPOSSIBLE"<<endl;
}
}
return 0;
}
【例题 8-4 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
贪心+优先队列+问题分解 对x,y 分开处理 当 xl<cnt(当前处理行)时,不能简单的选择cnt,而是应该让xl=cnt 并重新加入优先队列.(y的处理同上) #include <io ...
- 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辆车的所能在的矩阵的范 ...
随机推荐
- 【python下使用OpenCV实现计算机视觉读书笔记2】图像与字节的变换
import cv2 import numpy import os # Make an array of 120,000 random bytes. randomByteArray = bytearr ...
- UE4的JSON读写方式<一>
声明:全部权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/41009343 UE4的Json的解析博客地址: http:// ...
- sp_executesql invalid object name
https://stackoverflow.com/questions/10417126/dynamically-named-temp-table-returns-invalid-object-nam ...
- LDAP实现企业异构平台的统一认证
LDAP实现企业异构平台的统一认证 技术是为应用服务的,没有应用,技术就无用武之地.同样光配置完LDAP服务器没有任何意义,只有把所有需要认证的环节,只有纳入LDAP系统中,才能使它发挥应有 ...
- AIX 系统补丁升级步骤
AIX 系统补丁升级步骤 1.升级之前建议备份 rootvg (推荐) # smit mksysb 2.检查系统版本号 # oslevel -r 3.找到补丁光盘或者下载补丁,上传到服务器 ...
- mescroll报错
1.Cannot read property 'insertBefore' of null:说明你的容器id未找到,应确认你的容器id名与你NEW的容器名一致:
- 【Docker入门】
目录 Linux容器 Docker的优势 Docker三大概念 安装使用Docker 补充知识 [Docker入门] 发布文章 "qq_41964425" @ *** 所谓Dock ...
- Android布局之LinearLayout
LinearLayout 1.核心属性 高度:layout_height (基于内容 wrap_content:基于父控件:) 宽度:layout_width 方向:orientation (纵 ...
- XML解析——SAX解析以及更方便的解析工具(JDOM、DOM4J)
XML主要用于数据交换,HTML则用于显示. 相对于DOM的树形解析,SAX采用的是顺序解析,这种解析方法可以快速地读取XML数据的方式. SAX主要事件: No. 方法 类型 描述 1 public ...
- 转:mac环境下使用svn
在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境.在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,不过还 ...