【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

显然把问题分解成两个子问题。
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的更多相关文章

  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

    贪心+优先队列+问题分解 对x,y 分开处理 当 xl<cnt(当前处理行)时,不能简单的选择cnt,而是应该让xl=cnt 并重新加入优先队列.(y的处理同上) #include <io ...

  9. UVa 11134 Fabled Rooks(贪心)

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

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

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

随机推荐

  1. Redis封装之String

    RedisBase类 /// <summary> /// RedisBase类,是redis操作的基类,继承自IDisposable接口,主要用于释放内存 /// </summary ...

  2. 1.windows编程常用

    1.画线 HDC hdc; hdc = ::GetDC(m_hWnd); ::MoveToEx(hdc, , , NULL); ::LineTo(hdc, , ); 2.填充矩形 HDC hdc; h ...

  3. vSphere5安装配置视频教程

    vSphere5安装配置视频教程 本文出自 "李晨光原创技术博客" 博客,请务必保留此出处http://chenguang.blog.51cto.com/350944/819550

  4. javascript中 visibility和display的区别

    visibility属性用来确定元素是显示还是隐藏的,这用visibility="visible|hidden"来表示(visible表示显示,hidden表示隐藏). 当visi ...

  5. python requests请求卡住问题

    最近经常接到别人反馈某个爬虫工具程序没有正常运行,需要下载的资讯数据也没有及时进行收录. 刚开始以为可能是机器的问题,偶尔机器会出现程序运行中途卡住的情况. 但随着异常的情况越来越频繁,我便只好去排查 ...

  6. JSP页面的静态包含和动态包含的区别与联系

    JSP中有两种包含: 静态包含:<%@include file="被包含页面"%> 动态包含:<jsp:include page="被包含页面" ...

  7. CentOS-6.4-minimal版中安装JDK_Maven_Subversion以及改动rpm包安装路径

    完整版见https://jadyer.github.io/2013/09/07/centos-config-develop/ /** * @see -------------------------- ...

  8. [Python] Python list slice syntax fun

    # Python's list slice syntax can be used without indices # for a few fun and useful things: # You ca ...

  9. javaWeb自己定义可排序过滤器注解,解决Servlet3.0下@WebFilter注解无法排序问题

    com.lwl.anno 凝视类型 @WebFilterSort 须要用的jar包 http://download.csdn.net/detail/u013202238/9431110 用该注解注冊的 ...

  10. 自写的开发框架,胜于官方的clientAPP的实战开发。(已开源)

    已开源,欢迎大家fork 小弟github地址为https://github.com/10045125/vanda 好久没写博客了,这段时间主要是要做的事情太多.如今接触android有段时间了.非常 ...