三维拓扑排序好题hdu3231
/*
三维拓扑排序
将每个长方体分解成六个面,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的更多相关文章
- UVa 10305 - Ordering Tasks (拓扑排序裸题)
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- HDU3231 Box Relations——三维拓扑排序
HDU3231 Box Relations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题目意思:在一个三维空间上有一些棱和坐标轴平行的立方 ...
- 【拓扑排序】【HDU3231】【Box Relations】
题目大意: N个盒子 给你K个以下关系 1.A和B有重叠 2.A在B的左边且不重叠 3.A在B的前边且不重叠 4.A在B的上面且不重叠 显然单独分配X坐标处理2(x1<x2<x1'< ...
- HDU 1285 经典拓扑排序入门题
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- POJ2367 拓扑排序 裸题 板子题
http://poj.org/problem?id=2367 队列版 #include <stdio.h> #include <math.h> #include <str ...
- HDU1285-确定比赛名次-拓扑排序板子题
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
- POJ2367(拓扑排序裸题
#include<iostream> #include<vector> #include<queue> using namespace std; typedef l ...
- HDU 1285 确定比赛名次 拓扑排序模板题
http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <cstdio> #include <cstdlib> #inc ...
- POJ 2367 Genealogical tree 拓扑排序入门题
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8003 Accepted: 5184 ...
随机推荐
- Spring的常用工具类
官方文档 http://projects.spring.io/spring-framework https://docs.spring.io/spring/docs/current/javadoc-a ...
- Python 包
转载自https://www.cnblogs.com/feeland/p/4401758.html Python 包 包 定义 为了组织好模块,会将多个模块分为包.Python 处理包也是相当方便的. ...
- Java内存模型-final域的内存语义--没明白,预留以后继续理解
https://www.cnblogs.com/yuanfy008/p/9349275.html 来自 Java并发编程(1)-Java内存模型
- cxf方式实现webservice接口笔记
1.配置cxf的jar包依赖: 因maven中央仓库会自带cxf的相关依赖jar,故去maven官网搜索并获取pom配置到本地pom.xml文件即可,maven中央仓库搜索引擎地址:http://se ...
- LINQ Except “引用类型” 用法
值类型的比较Except 直接就比了 正经集合类型的如下 var resultExcept = Expert_ItemSource.Except(Invert_ItemSource, new MyCo ...
- canves绘制北京地铁线路图,包括线路绘制,优先路线,单路径选择。
canves绘制北京地铁线路图,包括线路绘制,优先路线,单路径选择. 即将推出,后台涵盖各种语言,php,C#,java,nodejs等.
- tar命令加密压缩
场景 Centos6下使用加密压缩,可以从A机器到B机器解压. 可用在kali上解压就不行. 命令 解包 tar zxvf FileName.tar 打包 tar czvf FileName.tar ...
- aiohttp的笔记之TCPConnector
TCPConnector维持链接池,限制并行连接的总量,当池满了,有请求退出再加入新请求.默认是100,limit=0的时候是无限制 1.use_dns_cache: 使用内部DNS映射缓存用以查询D ...
- MongoVUE 使用教程
MongoVUE是一款针对MongoDB的客户端工具,现在连接数据库也叫数据模式有2种方法,一种是B/S结构的数据库,通过网页就可以访问.另外一种就是基于C/S客户端的连接方式,本次为大家分享的这一个 ...
- 在Ubuntu 16.04下安装nodejs
源安装: 1.curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - 2.sudo apt-get install -y node ...