Box Relations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 894    Accepted Submission(s): 324
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 n lines 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
 
Recommend
chenrui   |   We have carefully selected several similar problems for you:  3236 3234 3237 3232 3233 
 
 //140MS    1276K    1924 B    G++
/* 题意:
给出n个矩阵的一系列的关系,输出满足关系的n个矩阵的对角坐标。 拓扑排序:
矩阵就有六个面,x、y、z各有两个面,设上表面为i+n,下表面为i,
然后每次的XYZ操作就是对x、y、z轴的上下表面进行拓扑排序,其中要
注意的一点就是I A B操作,要求A的上表面大于B的下表面,B的上表面
要大于A的下表面。 调试了挺久的。 */
#include<iostream>
#include<vector>
#include<queue>
#define N 2005
using namespace std;
int in[][N];
vector<int>V[][N];
int n,r,cas;
void init() //初始化
{
memset(in,,sizeof(in));
for(int ii=;ii<;ii++)
for(int i=;i<=*n;i++){
V[ii][i].clear();
}
for(int ii=;ii<;ii++)
for(int i=;i<=n;i++){
V[ii][i].push_back(i+n);
in[ii][i+n]++;
}
}
int topo(int x[],int id) //topo排序
{
queue<int>Q;
int ii=;
for(int i=;i<=*n;i++)
if(in[id][i]==)
Q.push(i);
//printf("*%d\n",Q.size());
while(!Q.empty()){
int t=Q.front();
Q.pop();
x[t]=++ii; //出来的先排
for(int i=;i<V[id][t].size();i++){
if(--in[id][V[id][t][i]]==)
Q.push(V[id][t][i]);
}
}
//printf("**%d\n",ii);
if(ii!=*n) return ;
return ;
}
void solve()
{
int a[][N]={}; //记录答案
int flag=;
for(int i=;i<;i++)
if(topo(a[i],i)) flag=;
if(flag) printf("Case %d: IMPOSSIBLE\n\n",cas++);
else{
printf("Case %d: POSSIBLE\n",cas++);
for(int i=;i<=n;i++)
printf("%d %d %d %d %d %d\n",a[][i],a[][i],a[][i],a[][i+n],a[][i+n],a[][i+n]);
printf("\n");
}
}
int main(void)
{
int a,b;
char op;
cas=;
while(scanf("%d%d%*c",&n,&r),n+r)
{
init();
for(int i=;i<r;i++){
scanf("%c%d%d%*c",&op,&a,&b);
if(op=='I'){
for(int ii=;ii<;ii++){
V[ii][a].push_back(b+n);
in[ii][b+n]++;
V[ii][b].push_back(a+n);
in[ii][a+n]++;
}
}else{
V[op-'X'][a+n].push_back(b);
in[op-'X'][b]++;
}
}
solve();
}
return ;
}

hdu 3231 Box Relations (拓扑排序)的更多相关文章

  1. HDU 3231 Box Relations

    题目大意: 给定一些正方体的关系,要求一组符合这些关系的正方体坐标,如果不存在符合条件的正方体坐标,IMPOSSIBLE.(Special Judge) 实力还是太弱了,完全不会…… #include ...

  2. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  3. hdu 5098 双队列拓扑排序

    http://acm.hdu.edu.cn/showproblem.php?pid=5098 软件在安装之后需要重启才能发挥作用,现在给你一堆软件(有的需要重启有的不需要)以及安装这个软件之前需要哪些 ...

  4. HDU 5811 Colosseo(拓扑排序+单调DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5811 [题目大意] 给出 一张单向图,现在将其划分成了两个部分,问划分之后的点是否分别满足按照一定 ...

  5. HDU 2647 Reward(拓扑排序+判断环+分层)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工 ...

  6. HDU 4857 (反向拓扑排序 + 优先队列)

    题意:有N个人,M个优先级a,b表示a优先于b.而且每一个人有个编号的优先级.输出顺序. 思路来自:与PKU3687一样 在主要的拓扑排序的基础上又添加了一个要求:编号最小的节点要尽量排在前面:在满足 ...

  7. HDU 4857 逃生(拓扑排序)

    拓扑排序 一.定义 对一个有向无环图(Directed Acyclic Graph简称DAG)G进行拓扑排序,是将G中所有顶点排成一个线性序列,使得图中任意一对顶点u和v,若<u,v> ∈ ...

  8. HDU 4857 逃生 【拓扑排序+反向建图+优先队列】

    逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  9. hdu 1811(缩点+拓扑排序+并查集)

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. 【解决】docker 容器中 consul集群问题处理

    现象描述:   node1 和node2 日志反复出现 add remove node3节点. node3 节点 一直 驳回 node1 和node2 认为node3已经dead的消息  不断重启se ...

  2. JS对象和数组在谷歌浏览器中引用存储的表现

    大家都知道JS的数据分为基本类型和引用类型.具体什么不说了,今天主要说说对象和数组作为引用类型在谷歌浏览器中的表现. 首先,问题是这么发现的.我在控制台使用console打印了一个数组,然后对数组进行 ...

  3. hibernate连接oracle数据库进行查询

    按主键查询 dao层 public Emp get(Serializable id){ //通过session的get方法根据加载指定对象 return (Emp)HibernateUtil.curr ...

  4. 【c学习-13】

    /*库函数 1:数学函数库:math.h abs():绝对值; acos(),asin(),atan():cos,sin,tan的倒数 exp():指数的次幂 pow(x,y):x的y次幂 log() ...

  5. python3笔记

    python3 Python3 基本数据类型 Python 中有六个标准的数据类型: Numbers(数字) Python可以同时为多个变量赋值,如a, b = 1, 2. 一个变量可以通过赋值指向不 ...

  6. Node.js中的不安全跳转如何防御详解

    Node.js中的不安全跳转如何防御详解 导语: 早年在浏览器大战期间,有远见的Chrome认为要运行现代Web应用,浏览器必须有一个性能非常强劲的Java引擎,于是Google自己开发了一个高性能的 ...

  7. Linux命令备忘录:quota显示磁盘已使用的空间与限制

    quota命令用于显示用户或者工作组的磁盘配额信息.输出信息包括磁盘使用和配额限制. 语法 quota(选项)(参数) 选项 -g:列出群组的磁盘空间限制: -q:简明列表,只列出超过限制的部分: - ...

  8. h5调试工具

    1.Safari:iPhone 调试利器,查错改样式首选: 2.iOS 模拟器:不需要真机,适合调试 Webview 和 H5 有频繁交互的功能页面: 3.Charles: Mac OS 系统首选的抓 ...

  9. 2,PyAudio 实现录音 自动化交互实现问答

    Python 很强大其原因就是因为它庞大的三方库 , 资源是非常的丰富 , 当然也不会缺少关于音频的库 关于音频, PyAudio 这个库, 可以实现开启麦克风录音, 可以播放音频文件等等,此刻我们不 ...

  10. 使用FPGA开发板驱动VGA显示器

    1. 本次使用的是cyclone4开发板,先看下原理图,因为右边的RGB应该是模拟信号量,但是本次例程只接了3根线,那就是说颜色只有8种. 2. 代码,输出信号有R,G,B三色,就是上图右边的,行同步 ...