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与FastDFS的安装命令及使用

    Docker特点 1)上手快 用户只需要几分钟,就可以把自己的程序“Docker 化”.Docker 依赖于“写时复制” (copy-on-write)模型,使修改应用程序也非常迅速,可以说达到“随心 ...

  2. ECSHOP和SHOPEX快递单号查询顺丰插件V8.6专版

    发布ECSHOP说明: ECSHOP快递物流单号查询插件特色 本ECSHOP快递物流单号跟踪插件提供国内外近2000家快递物流订单单号查询服务例如申通快递.顺丰快递.圆通快递.EMS快递.汇通快递.宅 ...

  3. 中恳中笨 搭建flask封装环境

    话不多说,先干再说..... 打开pycharm,创建一个关于flask的项目 2.创建一个App的文件包 3.把staic和templates文件包拖进App里 4.把app.py文件改为manag ...

  4. python三大神器之迭代器

    可迭代协议: 内部含有__iter__方法的值/变量都是可迭代的.可迭代类型和python语言之间的协议. 可迭代对象: iterable,内部包含__iter__()函数. 迭代器: iterato ...

  5. jenkins邮件发送jmeter接口测试报告

    在Jenkins中配置实现邮件通知,Jenkins提供了两种方式的配置. 一种是Jenkins内置默认的邮件通知,但是它本身有很多局限性,比如它的邮件通知无法提供详细的邮件内容.无法定义发送邮件的格式 ...

  6. JavaScript之原型 Prototype

    1.我们所创建的每一个函数,解析器都会向函数中添加一个属性prototype.这个属性对应着一个对象,这个对象就是我们所谓的原型对象.如果函索作为普通函数调用prototype没有任何作用. 当函数以 ...

  7. IO复用——poll系统调用

    1.poll函数 #include<poll.h> int poll(struct pollfd* fds, nfds_t ndfs, int timeout) poll函数在一定的时间内 ...

  8. SAPFiori

    最新SAP Fiori常用事务代码持续更新中...谢谢支持   注意: 以 / 开头的事务码需要加/N或/O进入,否则进不去   SEGW:  创建Gateway Service   /UI2/FLP ...

  9. python2.7练习小例子(十五)

        15):题目:输出指定格式的日期.     程序分析:使用 datetime 模块.     程序源代码: #!/usr/bin/python # -*- coding: UTF-8 -*- ...

  10. RelativeSource设定绑定方向

    <Window x:Class="Yingbao.Chapter2.RelativeEx.AppWin" xmlns="http://schemas.microso ...