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. 使用公共的存储过程实现repeater的分页

    当一个项目repeater分页多的时候使用公共的存储过程实现分页,是不错的选择 ALTER PROC [dbo].[P_Common_proc] -- 通用分页存储过程 @TableName varc ...

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

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

  3. java递归 斐波那契数列递归与非递归实现

    递归简单来说就是自己调用自己, 递归构造包括两个部分: 1.定义递归头:什么时候需要调用自身方法,如果没有头,将陷入死循环 2.递归体:调用自身方法干什么 递归是自己调用自己的方法,用条件来判断调用什 ...

  4. Fabric go sdk初始化所需证书解析

    fabric sdk go 提供的官方文档少之又少,要想入门,主要就靠研究官方的e2e系列示例,这真的是一件挺无奈的事情.没法子,只能硬着头皮上了.研究发现,e2e这个例子是通过cryptogen生成 ...

  5. 记一次MD5妙用

    记一次MD5妙用 最近项目组中在做历史记录的改造工作,主持讨论了多次,但每次讨论完都觉的很完美了,但实际在写这部分逻辑的时候还是会发现一些问题出来,很难受,反反复复的暴露智商是硬伤,人艰不拆,暂先不扯 ...

  6. 集成运放输入电压范围指标参数Uicmax,Uidmax

    图中Uicmax最大共模输入电压:是运放能正常工作下的最大输入电压: Uidmax最大差模输入电压:是运放要损坏的最大输入电压

  7. Android面试收集录 Android系统的资源+其他

    1.Android应用程序的资源是如何存储的,如何使用? res文件夹或者assets文件夹 res目录中的资源在R类中生成一个int变量,然后再布局文件中可以直接使用,在代码中,要getResour ...

  8. 责任链模式的使用-Netty ChannelPipeline和Mina IoFilterChain分析

    本文来自网易云社区 作者:乔安然 1. Chain of Responsiblity 定义: 使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这个对象连成一条链,并沿着这条链 ...

  9. 3,SQL语句及数据库优化

       1,统一SQL语句的写法 对于以下两句SQL语句,程序员认为是相同的,数据库查询优化器认为是不同的. 所以封装成复用方法,用标准模板来控制. select*from dual select*Fr ...

  10. Android ImageSwitcher 配合Picasso解决内存溢出(OOM)问题

    最近项目中用到了 ImageSwitcher 来实现图片切换,使用起来很简单,但发现当图片比较大(超过了3M)时,程序出现了内存溢出(OOM)问题而崩溃了. 原因就是图片太大了,显示到 ImageVi ...