HDU3231 topology Ordering

Source: Internet
Author: User
Tags cas

Box relations

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1334 Accepted Submission (s): 540
Special Judge


Problem Descriptionthere is NBoxes C1, C2, ..., CnIn 3D space. The edges of the boxes is parallel to the x, yOr Z-axis. We provide some relations of the boxes, and your task is to construct a set of boxes satisfying all these relations.

There is four kinds of relations (1 <= i,j<= N, Iis 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 have smaller x-coordinate than any PO int inside Cj.

      • Y i j:the intersection volume is zero, and any point inside Ci have smaller y-coordinate than any PO int inside Cj.

    • Z I j:the intersection volume is zero, and any point inside Ci have smaller z-coordinate than any point Inside Cj.
.

Inputthere'll is at the most test cases. Each case begins with a line containing the integers N(1 <= N<=) and R(0 <= R<= 100,000), the number of boxes and the number of relations. Each of the following RLines describes a relation, written in the format above. The last test case was followed by N= R=0, which should not be processed.

Outputfor 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 NLines contains six integers x1, y1, Z1, x2, Y2, Z2 ,That means the I-th box is the set of points ( x, y) satisfying x1 <= x <= x2, y1 <= y <= y2, z1 <= z <= Z2. The absolute values of x1, y1, Z1, x2, y2, Z2should not exceed 1,000,000.

Print a blank line after the output of each test case.

Sample Input3 2I 1 2X 2 3Z 1 2Z 2 3Z 3 11 00 0

Sample outputcase 1:POSSIBLE0 0 0 2 2 1 1 3 3 8 8 9 9 9Case 2:impossiblecase 3:POSSIBLE0 0 0 1 1 1

Source2009 Asia Wuhan Regional Contest Hosted by Wuhan University test instructions: gives a positional relationship between n cubes, I, A, A and b for intersect, X, A, or X for a is less than the X coordinate of B, output Coordinate range code for the cube that meets the criteria:
//consider the six facets of a cube as 6 points, each with its own constraint (X1<X2,Y1<Y2,Z1<Z2), and the cube//constraints, so that three-dimensional coordinates are divided into three parts of the map, topological sorting, ranked in the back of more than 1 units in front of the length of the line.#include <iostream>#include<cstdio>#include<cstring>#include<queue>#include<vector>using namespacestd;Const intmaxn=2005;intNminch[3][maxn],val[3][maxn];vector<int>g[3][MAXN];voidinit () { for(intI=0;i<3; i++){         for(intj=1; j<=n*2; j + +){            inchI [j]=val[i][j]=0;        G[i][j].clear (); }    }     for(intI=0;i<3; i++){         for(intj=1; j<=n;j++){            inchI [j+n]++; G[i][j].push_back (J+N); }    }}BOOLtopo () { for(intI=0;i<3; i++) {Queue<int>Q; intCnt=0;  for(intj=1; j<=n;j++)        if(inchI [j]==0) {Val[i][j]=cnt++;        Q.push (j); }         while(!Q.empty ()) {            intA=Q.front (); Q.pop ();  for(intj=0;j< (int) G[i][a].size (); j + +){                intb=G[i][a][j]; VAL[I][B]=max (val[i][b],val[i][a]+1);//!                if(--inchI [b]==0) {Q.push (b); CNT++; }            }        }        if(cnt!=n*2)return 0; }    return 1;}intMain () {intcas=0;  while(SCANF ("%d%d", &n,&m) && (n+m))        {init (); Charch[5];intb;  while(m--) {scanf ("%s%d%d",ch,&a,&b); if(ch[0]=='I'){                 for(intI=0;i<3; i++){                    inchI [A+n]++;g[i][b].push_back (A +N); inchI [B+n]++;g[i][a].push_back (b +N); }            }            Else if(ch[0]=='X'){                inch[0][b]++;g[0][a+N].push_back (b); }            Else if(ch[0]=='Y'){                inch[1][b]++;g[1][a+N].push_back (b); }            Else{                inch[2][b]++;g[2][a+N].push_back (b); }} printf ("Case %d:",++CAs); if(Topo ()) {printf ("possible\n");  for(intI=1; i<=n;i++) printf ("%d %d%d%d%d%d\n", val[0][i],val[1][i],val[2][i],val[0][i+n],val[1][i+n],val[2][i+n]); }        Elseprintf"impossible\n"); printf ("\ n"); }    return 0;}

HDU3231 topology Ordering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.