多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > HDU3231 Box Relations(拓撲排序)經典

HDU3231 Box Relations(拓撲排序)經典

來源:程序員人生   發布時間:2015-06-16 08:51:31 閱讀次數:4051次

Box Relations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1042    Accepted Submission(s): 389
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 <= n, i 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
2009 Asia Wuhan Regional Contest Hosted by Wuhan University 

題意:

在3維空間內,有n個長方體,棱都與坐標軸平行。給出1些關系,問是不是可能,若可能,輸出其中的1種。

關系有兩種:

1、I:兩個長方體有相交的體積。

2、X或Y或Z:某個長方體的所有點的某1維(X或Y或Z)的坐標完全小于另外一個長方體的任意1點。

#include<stdio.h> #include<vector> #include<queue> using namespace std; const int N = 2005; vector<int>mapt[3][N]; int in[3][N],v[3][N],n; void init() { for(int i=0;i<3;i++) for(int j=1;j<=n*2;j++) in[i][j]=v[i][j]=0,mapt[i][j].clear(); for(int i=0;i<3;i++)//坐標X,Y,Z for(int j=1;j<=n;j++)//盒子j,用兩個點表示,點j與點j+n { in[i][j+n]++; mapt[i][j].push_back(j+n); //點j的坐標比相應的點j+n坐標值小 } } int topeSort() { for(int i=0;i<3;i++) { int k=0; queue<int>q; for(int j=1;j<=n;j++) if(in[i][j]==0) q.push(j),v[i][j]=k++; while(!q.empty()) { int s=q.front(); q.pop(); int len=mapt[i][s].size(); for(int j=0; j<len; j++) { int tj=mapt[i][s][j]; in[i][tj]--; if(v[i][s]+1>v[i][tj]) v[i][tj]=v[i][s]+1; if(in[i][tj]==0) q.push(tj),k++; } } if(k!=n*2) return 0; } return 1; } int main() { char ch[5]; int m,a,b,cas=0; while(scanf("%d%d",&n,&m)>0&&n+m!=0) { init(); while(m--) { scanf("%s%d%d",ch,&a,&b); if(ch[0]=='I') { for(int i=0;i<3;i++) { mapt[i][a].push_back(b+n); in[i][b+n]++; mapt[i][b].push_back(a+n); in[i][a+n]++; } } else if(ch[0]=='X') mapt[0][a+n].push_back(b),in[0][b]++; else if(ch[0]=='Y') mapt[1][a+n].push_back(b),in[1][b]++; else if(ch[0]=='Z') mapt[2][a+n].push_back(b),in[2][b]++; } printf("Case %d: ",++cas); if(topeSort()==0) printf("IMPOSSIBLE "); else { printf("POSSIBLE "); for(int i=1;i<=n;i++) { printf("%d",v[0][i]); for(int j=1;j<3;j++) printf(" %d",v[j][i]); for(int j=0;j<3;j++) printf(" %d",v[j][i+n]); printf(" "); } } printf(" "); } }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲毛片在线 | 好吊色永久免费视频大全 | 欧美人与动人物xxxx9296 | 欧美人与性另类 | 久久精品这里是免费国产 | 不卡欧美 | 图片小说亚洲 | 欧美三区在线观看 | 国产亚洲视频在线播放大全 | 看毛片网站 | 日韩 欧美 自拍 在线 视频 | 亚洲国产日韩在线一区 | 欧美最猛黑人xxxx黑人猛交98 | 国产精品一级视频 | 欧美3区 | 男女午夜爽爽大片免费 | 欧美日韩福利视频一区二区三区 | 成年人视频在线观看免费 | 99久久精品国产综合男同 | 午夜肉伦伦影院 | www.99精品视频在线播放 | 欧洲黄色毛片 | 在线观看中文字幕亚洲 | 亚洲视频自拍 | 中文字幕观看 | 亚洲一区免费看 | 三浦惠理子中文字幕在线一区二区 | 成人性视频在线三级 | 福利第一页 | 免费视频不卡一区二区三区 | 一级特黄aa大片免费 | 亚洲高清视频在线 | 午夜影院h | 国产在线精品福利一区二区三区 | 欧美成人精品福利在线视频 | 亚洲网站视频在线观看 | 欧美激情精品久久久久久久九九九 | 国产一区二区在线视频观看 | 国产成人免费不卡在线观看 | 亚洲国产欧美精品一区二区三区 | 国产精品自在线 |