【例题 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辆车的所能在的矩阵的范 ...
随机推荐
- json数据转化成实体 存到数据库.
直接看步骤吧 1.一般我们会调用别人给的webservice获取一个字符串数据.如果为String data="xxxxxxxxxx"; 这个data事实上就是样例Enterpr ...
- PHP长整型在32位系统中强制转化溢出
CleverCode近期遇到一个PHP项目整形转化问题,mysql有一个字段id是bigint的,里面有长整型,如id = 5147486396.可是php代码因为历史原因却部署在多台机器中,当中A机 ...
- Dubbo源代码分析(三):Dubbo之服务端(Service)
如上图所看到的的Dubbo的暴露服务的过程,不难看出它也和消费者端非常像,也须要一个像reference的对象来维护service关联的全部对象及其属性.这里的reference就是provider. ...
- 静态时序分析SAT
1. 背景 静态时序分析的前提就是设计者先提出要求,然后时序分析工具才会根据特定的时序模型进行分析,给出正确是时序报告. 进行静态时序分析,主要目的就是为了提高系统工作主频以及增加系统的稳定性.对 ...
- CORS with Spring MVC--转
原文地址:http://dontpanic.42.nl/2015/04/cors-with-spring-mvc.html CORS with Spring MVC In this blog po ...
- 开源3D游戏引擎Irrlicht简介
Irrlicht简介 Irrlicht在国内也被叫做"鬼火"引擎,是一款用C++编写的开放源代码的高性能游戏引擎.而且是跨平台的,具有很好的移植性,Irrlicht支持OpenGl ...
- 如何利用Python网络爬虫抓取微信好友数量以及微信好友的男女比例
前几天给大家分享了利用Python网络爬虫抓取微信朋友圈的动态(上)和利用Python网络爬虫爬取微信朋友圈动态——附代码(下),并且对抓取到的数据进行了Python词云和wordart可视化,感兴趣 ...
- Bootstrap Table 的用法
记录下 Bootstrap Table 的用法,备忘. <!DOCTYPE html> <html> <head> <meta charset="u ...
- Tensorflow 学习笔记 -----tf.where
TensorFlow函数:tf.where 在之前版本对应函数tf.select 官方解释: tf.where(input, name=None)` Returns locations of true ...
- 【Henu ACM Round#14 C】Duff and Weight Lifting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 2^y可以由两个2^(y-1)相加得到. 则有一个贪心的策略. 就是2^x尽量都变成2^(x+1) (即能够凑就尽量凑) 如果x还有 ...