UVA 11134Fabled Rooks
来源:互联网 发布:上海金慧软件 编辑:程序博客网 时间:2024/06/08 09:31
题目大意:给出n行n列的表,输入4个数字代表点的范围,范围是一个矩形,前俩个数字代表矩形左上角坐标,后俩个数字代表右下角坐标,要求取的点所在行和所在列与其他点不相交
解题思路:因为行和列不冲突,所以将每个点分为行和列单独讨论,将得到的每个点范围按最大值从小到达排列,然后贪心处理
#include <iostream>#include <cstring>#include <algorithm>using namespace std;struct node { int num, a, b; //a, b为x范围或者y范围,num是编号};bool cmp(node p, node q) { return p.b < q.b;}int n;int rex[6000], rey[6000];node nodex[6000];node nodey[6000];int sol() { for(int i = 1; i <= n; i++) { int k = 0; int j; for(j = 0; j <n ;j++) { int numb = nodex[j].num; if(rex[numb]) continue; if(nodex[j].a <= i && nodex[j].b >= i) { rex[numb] = i; k = 1; break; } } if(!k) return 0; k = 0; for(j = 0; j <n ;j++) { int numb = nodey[j].num; if(rey[numb]) continue; if(nodey[j].a <= i && nodey[j].b >= i) { rey[numb] = i; k = 1; break; } } if(!k) return 0; } return 1;}int main() { while(cin >> n && n) { memset(rex, 0, sizeof(rex)); memset(rey, 0, sizeof(rey)); for(int i = 0; i < n; i++) { cin >> nodex[i].a; cin >> nodey[i].a; cin >> nodex[i].b; cin >> nodey[i].b; nodex[i].num = i+1; nodey[i].num = i+1; } sort(nodex, nodex+n, cmp); sort(nodey, nodey+n, cmp); if(sol()) { for(int i = 1; i <= n; i++) { cout << rex[i] << " " << rey[i] << endl; } } else { cout << "IMPOSSIBLE" << endl; } } return 0;}
阅读全文
0 0
- uva 11134 Fabled Rooks
- Uva-11134-Fabled Rooks
- uva 11134 Fabled Rooks
- uva 11134 - Fabled Rooks
- UVA 11134 - Fabled Rooks
- UVa:11134 Fabled Rooks
- uva 11134 Fabled Rooks
- UVa 11134 - Fabled Rooks
- UVa 11134 Fabled Rooks
- UVA 11134 - Fabled Rooks
- Uva - 11134 - Fabled Rooks
- UVA - 11134 Fabled Rooks
- UVA 11134 Fabled Rooks
- UVA - 11134 Fabled Rooks
- UVA 11134 Fabled Rooks
- UVA 11134 Fabled Rooks
- UVA 11134Fabled Rooks
- Uva 11134 Fabled Rooks
- Android中的Fragment
- No FileSystem for scheme: hdfs
- 数据结构1————栈的概念和运算
- c# OpenGL 简单画点
- 如何解析读取excel数据
- UVA 11134Fabled Rooks
- 猴子吃桃问题
- libopencv_videoio.so: undefined reference to `av_free@LIBAVUTIL_52'
- web开发中获取的各种高度和宽度
- Java基础——JSP(二)
- 【备忘】2017年极客学院大数据工程师全套 视频 代码 课件
- PL/SQL 乱码问题
- 【CUGBACM15级BC第二场 A】hdu 4883 TIANKENG’s restaurant
- Linux -soname深入理解