/*
三维拓扑排序
将每个长方体分解成六个面,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. 【tmos】使用joda-time来个格式化时间

    代码 @Test public void test(){ DateTime dateTime = new DateTime(); String str = dateTime.toString(&quo ...

  2. IActionResult的返回类型

    ActionResult继承了IActionResult JsonResult.RedirectResult.FileResult.ViewResult.ContentResult均继承了Action ...

  3. MongoDB 学习手册 - CURD

    mongoDB 增加数据 // mongoDB 增加数据: //新增数据insert( 字典 ) 表示插入一条数据,insert([字典]) 表示插入多条数据 // db.text01.insert( ...

  4. 使用 JavaScript 将网站后台的数据变化实时更新到前端

    问:难道只能设置定时器每隔一秒通过 Ajax 向后台请求数据来实现吗? 答: 1. nodejs的 http://socket.io 支持上述 李宏训 所说的三种方式,另外还支持 Flash Sock ...

  5. shell编程 之 echo命令和printf命令

    1 echo命令基本情况: echo显示普通字符:echo "i am studying shell"(有木有引号都可以) 支持转义字符:echo "\"hel ...

  6. 集合-HashSet

    参考博客:https://www.cnblogs.com/runwulingsheng/p/5208762.html https://www.cnblogs.com/ysocean/p/6555373 ...

  7. 使用Office Online Server在线预览Office

    微软官方文档介绍 ⒈介绍 Office Online Server是 Office Web Apps Server 的升级版本,安装环境必须为两台Windows Server 2012 R2 或 Wi ...

  8. 高手进阶,终极内存技术指南——完整/进阶版 II (转)【转】

    转自:https://blog.csdn.net/lightseed/article/details/4630170 SDRAM芯片的预充电与刷新操作 预充电 由于SDRAM的寻址具体独占性,所以在进 ...

  9. RPC与实践(thrift在windows的编译/安装--c++版)

    ------------------------------------------------------------------------ RPC 功能目标 RPC 的主要功能目标是让构建分布式 ...

  10. [IOI2000] 邮局

    ## 非常神仙的 wqs 二分优化dp,又学了一招. 首先我们需要先想到一个人类智慧版的前缀和优化. # part 1:violence 然鹅在前缀和优化之前我们先考虑暴力做法:我们可以枚举 i . ...