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. 通过Ops Manager安装管理mongodb-3.4集群

    node1 Ops Manager,mongodb,agent node2 mongodb,agent node3 mongodb,agent 参考文档 https://docs.opsmanager ...

  2. Struts2拦截器说明

    有关于Struts2的拦截器的原理 在此共设置了两个拦截器,firstInterception.SecondInterception package struts2_inteception; publ ...

  3. JavaScript--Dom操作元素的样式

    在前端开发中,有时候需要动态修改的网页元素的样式,这里将使用JS动态修改元素样式的方法做个小结: 网页结构: 按钮: 标签:input    类型:button     id:btn          ...

  4. FROM_UNIXTIME

    FROM_UNIXTIME 格式化MYSQL时间戳函数   函数:FROM_UNIXTIME作用:将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示.语法 ...

  5. mysql根据二进制日志恢复数据/公司事故实战经验

    根据二进制日志恢复 目的:恢复数据,根据二进制日志将数据恢复到今天任意时刻 增量恢复,回滚恢复 如果有备份好的数据,将备份好的数据导入新数据库时,会随着产生二进制日志 先准备一台初始化的数据库 mys ...

  6. django开发傻瓜教程-3-celery异步处理

    Ref: https://www.jianshu.com/p/6f8576a37a3e https://blog.csdn.net/Demo_3/article/details/78119951 ht ...

  7. python文件操作(2017-8-5)

    一.打开文件 open(文件名,模式,编码)#默认模式为只读 f = open("c:/asd.txt") date = f.read() f.close() print(date ...

  8. Linux mysql启动与关闭

    service mysql stop service mysqld start

  9. ThinkPhP html原样入库

    开始正式搞php,在配置好PHP环境之后,从学习thinkphp框架开始php之旅. 在实际项目中需要将一个网页的html保存到数据库中,但不能被转义.由于thinkphp的数据库操作为通过他们自己O ...

  10. python2.7练习小例子(十七)

        17):题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字.例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘控制.     程序分析: ...