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. CsvHelper文档-1前言

    CsvHelper文档-1前言 英文文档链接地址:CsvHelper Document 开源项目地址:CsvHelper 翻译于2018-1-5,原本可能会随时更新: 每一段代码都是经过我实际测试的, ...

  2. adb 在windows7中的使用

    我的系统环境是win7 x64 首先放上资源链接:https://pan.baidu.com/s/1eTV5qX8 密码:2ejw 第一步: 配置环境变量,将adb.exe的路径添加到PATH里面去: ...

  3. Halcon10 下载

    Halcon10 下载地址:http://www.211xun.com/download_page_1.html HALCON 10 是一套机器视觉图像处理库,由一千多个算子以及底层的数据管理核心构成 ...

  4. 【机器学习】线性回归python实现

    线性回归原理介绍 线性回归python实现 线性回归sklearn实现 这里使用python实现线性回归,没有使用sklearn等机器学习框架,目的是帮助理解算法的原理. 写了三个例子,分别是单变量的 ...

  5. C#调用mingw的so库时无法加载DLL###.so 找不到指定的模块

    使用C#调用mingw的so,报了c# 无法加载DLL“###.so”,: 找不到指定的程序. (异常来自 HRESULT:0x8007007E)开始以为是dll路径问题,使用全路径确认正确后仍然无法 ...

  6. HDU 3262/POJ 3829 Seat taking up is tough(模拟+搜索)(2009 Asia Ningbo Regional)

    Description Students often have problems taking up seats. When two students want the same seat, a qu ...

  7. 硬件PCB Layout布局布线Checklist检查表(通用版)

    按部位分类 技术规范内容 1 PCB布线与布局 PCB布线与布局隔离准则:强弱电流隔离.大小电压隔离,高低频率隔离.输入输出隔离.数字模拟隔离.输入输出隔离,分界标准为相差一个数量级.隔离方法包括:空 ...

  8. java日期格式处理

    继承关系:java.lang.Object->java.text.Format->java.text.DateForm->java.text.SimpleDateFormat 日期代 ...

  9. 使用WCF上传数据

    通过传递Stream对象来传递大数据文件,但是有一些限制: 1.只有 BasicHttpBinding.NetTcpBinding 和 NetNamedPipeBinding 支持传送流数据. 2. ...

  10. 在临床医学里面,bid、tid、qid和q3w是什么意思啊??这些缩写的全称是怎么写呢??

    { value: 'QD', name: 'QD 每日一次' }, { value: 'BID', name: 'BID 每日两次' }, { value: 'TID', name: 'TID 每日三 ...