/*
三维拓扑排序
将每个长方体分解成六个面,xyz三维进行操作
每一维上的的所有长方体的面都应该服从拓扑关系,即能够完成拓扑排序
=如果两个长方体的关系时相交,那么其对应的三对面只要交叉即可 如 a1 b1 a2 b2
反之对应的那对面不可以交叉 如a1 a2 b1 b2
同时长方体自身的对应两个面也具有拓扑关系
*/
#include<bits/stdc++.h>
using namespace std;
#define maxn 10005
struct Edge{int to,nxt;}edge[][maxn*];
int head[][maxn],tot[],in[][maxn],pos[][maxn];
int n,m;
void init(){
memset(head,-,sizeof head);
tot[]=tot[]=tot[]=;
}
void addedge(int k,int u,int v){
edge[k][tot[k]].to=v;
edge[k][tot[k]].nxt=head[k][u];
head[k][u]=tot[k]++;
} int solve(int k){//对第k维上的面进行拓扑排序
int cnt=;
queue<int>q;
for(int i=;i<=n*;i++)
if(in[k][i]==)
q.push(i);
while(!q.empty()){
int u=q.front();
q.pop();
cnt++;
for(int i=head[k][u];i!=-;i=edge[k][i].nxt){
int v=edge[k][i].to;
in[k][v]--;
if(in[k][v]==){
q.push(v);
pos[k][v]=pos[k][u]+;
}
}
}
if(cnt==*n)return ;
else return ;
} int main(){
int tt=;
while(cin>>n>>m && n){
init();
memset(in,,sizeof in);
memset(pos,,sizeof pos); for(int i=;i<;i++)//每个长方体自身的约数
for(int j=;j<=n;j++){
in[i][j+n]++;
addedge(i,j,j+n);
} while(m--){
char ch;
int u,v;
cin>>ch>>u>>v;
if(ch=='I'){
for(int i=;i<;i++){
in[i][u+n]++;
addedge(i,v,u+n);
in[i][v+n]++;
addedge(i,u,v+n);
}
}
else {
in[ch-'X'][v]++;
addedge(ch-'X',u+n,v);
}
} int ans0=solve();
int ans1=solve();
int ans2=solve();
if(ans1== || ans2== || ans0==){
printf("Case %d: IMPOSSIBLE\n\n",++tt);
continue;
}
printf("Case %d: POSSIBLE\n",++tt);
for(int i=;i<=n;i++){
printf("%d %d %d ",pos[][i],pos[][i],pos[][i]);
printf("%d %d %d\n",pos[][i+n],pos[][i+n],pos[][i+n]);
}
puts("");
}
}

三维拓扑排序好题hdu3231的更多相关文章

  1. UVa 10305 - Ordering Tasks (拓扑排序裸题)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  2. HDU3231 Box Relations——三维拓扑排序

    HDU3231 Box Relations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题目意思:在一个三维空间上有一些棱和坐标轴平行的立方 ...

  3. 【拓扑排序】【HDU3231】【Box Relations】

    题目大意: N个盒子 给你K个以下关系 1.A和B有重叠 2.A在B的左边且不重叠 3.A在B的前边且不重叠 4.A在B的上面且不重叠 显然单独分配X坐标处理2(x1<x2<x1'< ...

  4. HDU 1285 经典拓扑排序入门题

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. POJ2367 拓扑排序 裸题 板子题

    http://poj.org/problem?id=2367 队列版 #include <stdio.h> #include <math.h> #include <str ...

  6. HDU1285-确定比赛名次-拓扑排序板子题

    有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...

  7. POJ2367(拓扑排序裸题

    #include<iostream> #include<vector> #include<queue> using namespace std; typedef l ...

  8. HDU 1285 确定比赛名次 拓扑排序模板题

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <cstdio> #include <cstdlib> #inc ...

  9. POJ 2367 Genealogical tree 拓扑排序入门题

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8003   Accepted: 5184 ...

随机推荐

  1. jq的遍历关系元素方法集合

    children .children(selector) 返回被选元素的所有直接子元素,不返回文本节点: 下面例子:给level-2的子元素设置border.比较使用children和find htm ...

  2. 【如何使用jQuery】【jQuery弹出框】【jQuery对div进行操作】【jQuery对class,id,type的操作】【jquery选择器】

    1.如何使用jQuery jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的宗旨 ...

  3. mysql与linux ~ 磁盘分析与调优

    一 简介 谈谈磁盘IO的问题二 目的:如何进行IO性能问题的排查 二  linux角度   一 机械硬盘基本定义       寻道时间,表示磁头在不同磁道之间移动的时间(最耗时).       旋转延 ...

  4. Django学习手册 - reverse()反转URL

    前端: <h1>测试</h1> <a href="/ce_test/?id=1">1按键</a> <a href=" ...

  5. python练习 之 实践出真知 中心扩展法求最大回文子串 (leetcode题目)

    1 问题,给定一个字符串,求字符串中包含的最大回文子串,要求O复杂度小于n的平方. 首先需要解决奇数偶数的问题,办法是:插入’#‘,aba变成#a#b#a#,变成奇数个,aa变成#a#a#,变成奇数个 ...

  6. 【NLP CS224N笔记】Lecture 2 - Word Vector Representations: word2vec

    I. Word meaning Meaning的定义有很多种,其中有: the idea that is represented by a word,phrase,etc. the idea that ...

  7. win10家庭版多用户

    1.Windows 找不到gpedit.msc https://jingyan.baidu.com/article/54b6b9c08b08382d593b4747.html 2.win10家庭版 创 ...

  8. 【转】Python 面向对象(初级篇)

    [转]Python 面向对象(初级篇) 51CTO同步发布地址:http://3060674.blog.51cto.com/3050674/1689163 概述 面向过程:根据业务逻辑从上到下写垒代码 ...

  9. 判断HDFS文件是否存在

    hadoop判断文件是否存在 在shell中判断一个HDFS目录/文件是否存在 直接看shell代码: hadoop fs -test -e /hdfs_dirif [ $? -ne 0 ]; the ...

  10. 遇到一个json解码失败的问题

    今日批量导入游戏, 从别人接口拉去的字符串json_decode总是失败, 但是把log里面记录的解码失败的字符串copy出来单独解析,却可以成功. 排除了是字符编码的问题后, 还是不行, 百思不得其 ...