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. CSP201409-2:画图

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  2. 持续集成之TeamCity 配置

    xcopy /S /Y CodeFirstDemo\CodefirstDemo.Web D:\publish\welcome\Web

  3. opencart

    1. Deleting english language, what happens?   Disable English tab , category and products     1) Fir ...

  4. Razor语法和Razor引擎大全

    一.Razor语法 1.Razor的标识符 解释:@字符被定义为Razor服务器代码块的标识符,后面的表示是服务器代码了.web form中使用<%%>中写服务器代码一个道理.在vs工具里 ...

  5. 【alpha】Scrum站立会议第2次....10.17

    小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app 1.任务进度 成员 已完成 今日完成 李权 数据库设计 消息发送代码实现 于淼 注册.登录界面,以及登录界面后台代码.发 ...

  6. 在线api查询网站

    1.包含各种常用的语言 http://tool.oschina.net/apidocs

  7. oracle 9i 图文安装教程 oracle 9i 安装

    我的安装文件是ISO镜像文件,使用Virtual DAEMON Manager v 4.10打开: ora9i-1.iso ora9i-2.iso ora9i-3.iso 首先必须把上面三个镜像文件都 ...

  8. C#下Label的多行显示

    效果如图 1. tableLayout 三行两列 第一行 存放二维码的信息 第二行空白,用于分割 第三行存储LOGO信息 2. Lable4个,Dock属性都为Fill 第一列TextAlign使用M ...

  9. bpf程序

    bpf都是怎么起作用的? 记得bpf之前是绑定在bpf bpf作用在哪里呀?

  10. html超出不自动换行

    1.使用overflow: hidden把超出的内容进行隐藏: 2.然后使用white-space: nowrap设置内容不换行: 3.最后使用text-overflow: ellipsis设置超出内 ...