Box Relations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1334    Accepted Submission(s): 540
Special Judge

Problem Description
There are n boxes C1, C2, ..., Cn in 3D space. The edges of the boxes are parallel to the x, y or z-axis. We provide some relations of the boxes, and your task is to construct a set of boxes satisfying all these relations.

There are four kinds of relations (1 <= i,j <= ni is different from j):

    • I i j: The intersection volume of Ci and Cj is positive.
    • X i j: The intersection volume is zero, and any point inside Ci has smaller x-coordinate than any point inside Cj.
    • Y i j: The intersection volume is zero, and any point inside Ci has smaller y-coordinate than any point inside Cj.
  • Z i j: The intersection volume is zero, and any point inside Ci has smaller z-coordinate than any point inside Cj.

.

 
Input
There will be at most 30 test cases. Each case begins with a line containing two integers n (1 <= n <= 1,000) and R (0 <= R <= 100,000), the number of boxes and the number of relations. Each of the following R lines describes a relation, written in the format above. The last test case is followed by n=R=0, which should not be processed.
 
Output
For each test case, print the case number and either the word POSSIBLE or IMPOSSIBLE. If it's possible to construct the set of boxes, the i-th line of the following nlines contains six integers x1, y1, z1, x2, y2, z2, that means the i-th box is the set of points (x,y,z) satisfying x1 <= x <= x2, y1 <= y <= y2, z1 <= z <= z2. The absolute values of x1, y1, z1, x2, y2, z2 should not exceed 1,000,000.

Print a blank line after the output of each test case.

 
Sample Input
3 2
I 1 2
X 2 3
3 3
Z 1 2
Z 2 3
Z 3 1
1 0
0 0
 
Sample Output
Case 1: POSSIBLE
0 0 0 2 2 2
1 1 1 3 3 3
8 8 8 9 9 9
Case 2: IMPOSSIBLE
Case 3: POSSIBLE
0 0 0 1 1 1
 
Source
 题意:
给出n个立方体之间的位置关系,I a,b 表示a和b相交,X a,b 表示a的x坐标都小于b的x坐标,输出符合条件的立方体的坐标范围
代码:
//把立方体的六个面看成6个点,每个立方体都有自己的约束条件(x1<x2,y1<y2,z1<z2),立方体之间又有
//约束条件,这样三维坐标分成三部分建图,拓扑排序,排在后面的比排在前面的多加1单位长度.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int maxn=;
int n,m,in[][maxn],val[][maxn];
vector<int>g[][maxn];
void init()
{
for(int i=;i<;i++){
for(int j=;j<=n*;j++){
in[i][j]=val[i][j]=;
g[i][j].clear();
}
}
for(int i=;i<;i++){
for(int j=;j<=n;j++){
in[i][j+n]++;
g[i][j].push_back(j+n);
}
}
}
bool topo()
{
for(int i=;i<;i++){
queue<int>q;
int cnt=;
for(int j=;j<=n;j++)
if(in[i][j]==){
val[i][j]=cnt++;
q.push(j);
}
while(!q.empty()){
int a=q.front();q.pop();
for(int j=;j<(int)g[i][a].size();j++){
int b=g[i][a][j];
val[i][b]=max(val[i][b],val[i][a]+);//!
if(--in[i][b]==){
q.push(b);cnt++;
}
}
}
if(cnt!=n*) return ;
}
return ;
}
int main()
{
int cas=;
while(scanf("%d%d",&n,&m)&&(n+m)){
init();
char ch[];int a,b;
while(m--){
scanf("%s%d%d",ch,&a,&b);
if(ch[]=='I'){
for(int i=;i<;i++){
in[i][a+n]++;g[i][b].push_back(a+n);
in[i][b+n]++;g[i][a].push_back(b+n);
}
}
else if(ch[]=='X'){
in[][b]++;g[][a+n].push_back(b);
}
else if(ch[]=='Y'){
in[][b]++;g[][a+n].push_back(b);
}
else{
in[][b]++;g[][a+n].push_back(b);
}
}
printf("Case %d: ",++cas);
if(topo()){
printf("POSSIBLE\n");
for(int i=;i<=n;i++)
printf("%d %d %d %d %d %d\n",val[][i],val[][i],val[][i],val[][i+n],val[][i+n],val[][i+n]);
}
else printf("IMPOSSIBLE\n");
printf("\n");
}
return ;
}

HDU3231拓扑排序的更多相关文章

  1. HDU3231 Box Relations——三维拓扑排序

    HDU3231 Box Relations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题目意思:在一个三维空间上有一些棱和坐标轴平行的立方 ...

  2. hdu3231 (三重拓扑排序) 2009 Asia Wuhan Regional Contest Hosted by Wuhan University

    这道题算是我拓扑排序入门的收棺题了,卡了我好几天,期间分别犯了超时,内存溢出,理解WA,细节WA,格式WA…… 题目的意思大概是在一个三维坐标系中,有一大堆矩形,这些矩形的每条棱都与坐标轴平行. 这些 ...

  3. 【拓扑排序】【HDU3231】【Box Relations】

    题目大意: N个盒子 给你K个以下关系 1.A和B有重叠 2.A在B的左边且不重叠 3.A在B的前边且不重叠 4.A在B的上面且不重叠 显然单独分配X坐标处理2(x1<x2<x1'< ...

  4. 三维拓扑排序好题hdu3231

    /* 三维拓扑排序 将每个长方体分解成六个面,xyz三维进行操作 每一维上的的所有长方体的面都应该服从拓扑关系,即能够完成拓扑排序=如果两个长方体的关系时相交,那么其对应的三对面只要交叉即可 如 a1 ...

  5. 算法与数据结构(七) AOV网的拓扑排序

    今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...

  6. 有向无环图的应用—AOV网 和 拓扑排序

    有向无环图:无环的有向图,简称 DAG (Directed Acycline Graph) 图. 一个有向图的生成树是一个有向树,一个非连通有向图的若干强连通分量生成若干有向树,这些有向数形成生成森林 ...

  7. 【BZOJ-2938】病毒 Trie图 + 拓扑排序

    2938: [Poi2000]病毒 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 609  Solved: 318[Submit][Status][Di ...

  8. BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)

    题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...

  9. 图——拓扑排序(uva10305)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

随机推荐

  1. 从零开始的Python学习Episode 1

    一.输入与输出 1.输入 input("number:") num = input("number:") 下面一段可以把输入的信息存在num中. 注意:输入的信 ...

  2. 将System.Drawing.Bitmap转换为Direct2D.D2DBitmap

    最近在尝试Direct2D编程,挺好玩的. 但是有时候还是会用到GDI+来生成图片,但D2D绘图需要用到自己的D2DBitmap类. 因此需要转换,查阅了下网上的资料,写了这么一个方法: using ...

  3. 深入理解Java 8 Lambda(类库篇——Streams API,Collectors和并行)

    转载:http://zh.lucida.me/blog/java-8-lambdas-inside-out-library-features/ 关于 深入理解 Java 8 Lambda(语言篇——l ...

  4. python函数中的位置参数、默认参数、关键字参数、可变参数区别

    一.位置参数 调用函数时根据函数定义的参数位置来传递参数. #!/usr/bin/env python # coding=utf-8 def print_hello(name, sex): sex_d ...

  5. 手机站测试工具(node服务器)

    最近在工作中遇到手机站测试的问题,于是就写了一个node服务外加一个第三方的转二维码功能,欢迎拍砖~ 项目地址:https://github.com/finderL/webserver

  6. “Hello world!”贡献分分配规则

    规则1:得到总分后取14分,剩下分数进行平分.(备注:例如得了50分,取出14分,剩下36分组内进行平分) 规则2:对于会议准时参加者每人加0.5分.(备注:按通知开会时间为准,准时到者实行加分.) ...

  7. Alpha-1

    前言 失心疯病源1 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 10:00~13:00 OpenCV环境配置,Matlab工具包下载 15:40~17:1 ...

  8. lintcode-149-买卖股票的最佳时机

    149-买卖股票的最佳时机 假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格.如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润. 样例 给出一个数组样例 [3 ...

  9. TCP系列05—连接管理—4、TCP连接的ISN、连接建立超时及TCP的长短连接

    一.TCP连接的ISN         之前我们说过初始建立TCP连接的时候的系列号(ISN)是随机选择的,那么这个系列号为什么不采用一个固定的值呢?主要有两方面的原因 防止同一个连接的不同实例(di ...

  10. oracle的SQL语句中的(+)是干什么用的?

    Oracle中的(+) 是外连接,如果在等号的左边就是左连接 和如果在等号的右边就是右连接 和left join ,right join 比较相似.....where sn (+) ='5620030 ...