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. CentOS 7.4使用yum源安装php7.2

    1.如果之前已经安装我们先卸载一下 yum -y remove php* 2.由于linux的yum源不存在php7.x,所以我们要更改yum源 rpm -Uvh https://dl.fedorap ...

  2. 虚拟环境管理之virtualenvwrapper

    上一篇写了下在linux上使用python的虚拟环境, 干脆把virtualenvwrapper也写一下 1.为什么要用virtualenvwrapper virtualenv 的一个最大的缺点就是: ...

  3. spring-运行时值注入

    在项目中经常使用连接数据库的配置,如下所示 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDa ...

  4. Linux 用户 和 组 快速了解

    1用户 (Linux中“只有超级管理员”才有权限操作 用户 和组) 1.1添加用户 useradd 命令 例如 :useradd hly //添加了一个新账户 hly 用户添加后 会存放在一个文件中, ...

  5. 怎么修复网站漏洞 骑士cms的漏洞修复方案

    骑士CMS是国内公司开发的一套开源人才网站系统,使用PHP语言开发以及mysql数据库的架构,2019年1月份被某安全组织检测出漏洞,目前最新版本4.2存在高危网站漏洞,通杀SQL注入漏洞,利用该网站 ...

  6. latex03-LaTeX中的中文处理办法

    编译含中文的tex文件的前提有三个: 默认编译器为XeLaTeX: 编辑器的默认字体编码格式为UTF-8: 引入ctex的宏包. 效果: 源码: %导言区 \documentclass{article ...

  7. golang的加法比C快?

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/142 1.31 晚上的火车回家,在公司还剩两个小时,无心工作,本 ...

  8. JENKINS系统的安装部署

    JENKINS 安装使用文档 简介 Jenkins是一个功能强大的应用程序,允许持续集成和持续交付项目,无论用的是什么平台.这是一个免费的源代码,可以处理任何类型的构建或持续集成,集成Jenkins可 ...

  9. PIC32MZ 通过USB在线升级 -- USB CDC bootloader

    了解bootloader 的实现,请加QQ: 1273623966 (验证填 bootloader):欢迎咨询或定制bootloader:我的博客主页www.cnblogs.com/geekygeek ...

  10. MyEclipse - 问题集 - 创建Maven项目,JDK版本默认是1.5

    修改Maven的配置文件settings.xml,增加profile节点,如下所示: <profile> <id>jdk-1.8</id> <activati ...