hdu3231 (triple topology sort)

Source: Internet
Author: User

This problem is my topological sort of the beginning of the collection of the coffin, card me for several days, during the time of the separate committed timeout, memory overflow, Understanding WA, Details WA, Format wa ...

The title is probably in a three-dimensional coordinate system with a large stack of rectangles, each of which is parallel to the axis.

There are 4 cases of these rectangles--

1. A coincident part (I a B) indicates that A is coincident with B;

2. A's x-coordinate is greater than the x-coordinate of B (x a B), indicating that the maximum x-coordinate of a is greater than the smallest x-coordinate of B;

3. (y a b) y-coordinate, ibid.;

4. (z a b) z-coordinate, ibid.;

That is, we can decompose each rectangle AI in three directions--the upper plane A01 of AI and the lower plane a02 of AI parallel to the Xoy plane, parallel to the xoz plane of Ai's left plane A11 and Ai's right plane A12, The front plane A21 of the AI, parallel to the yoz plane, and the rear plane a22 of the AI.

Assuming (I a B), then A01 < B02, A02 < B01;

Assuming there is (X a B), then the A02 < b01 are represented;

Assuming there is (Y a B), then the A12 < B11 are represented;

Assuming there is (Y a B), then the A22 < B21 are represented;

At the same time, each rectangle has its own characteristics: A01 < A02, A11<aa2, A21 < A22;

Then we get a topological relationship on all three planes of the rectangle, and then sort the topology of the three planes separately, and if there is a group that is not satisfied, then the output is impossible.

1#include <cstdio>2#include <cstring>3#include <queue>4 using namespacestd;5 6 Const intN =1010;7 Const intM =100010;8 9 structNodeTen { One     intval[3]; A     intds[3]; -}s[n<<2];//Save the coordinate values and depth of each plane (several planes in front) -  the structnode - { -     intto ; -     intNext; +}eage[3][m<<1];//relationships between each set of planes -  + intN, M; A intA, B; at Charch[2]; - inthead[3][m<<1];  - intTM =1; - intk[3]; -  - BOOLTsort (intx) in { -queue<int>que; to  +     intsum =0; -      for(inti =2; I <=2*n+1; i++) the     { *         if(S[i].ds[x] = =0) $         {Panax Notoginseng Que.push (i); -S[I].VAL[X] =0; the         } +     } A      while(!que.empty ()) the     { +         intp =Que.front (); - Que.pop (); $s[p].ds[x]--; $sum++; -  -          for(inti = head[x][p]; I! =-1; i =eage[x][i].next) the         { -             intv =eage[x][i].to;Wuyis[v].ds[x]--; the             if(S[v].ds[x] = =0) -             { Wu Que.push (v); -S[V].VAL[X] = s[p].val[x]+1; About             } $         } -     } -     if(Sum = =2*n)return 1; -     return 0; A } +  the void Get(intXintAintb) - { $Eage[x][k[x]].to =b; theEage[x][k[x]].next =Head[x][a]; theHead[x][a] = k[x]++; thes[b].ds[x]++; the } -  in intMain () the { the     //freopen ("Test.txt", "R", stdin); About      while(~SCANF ("%d%d", &n, &m) && (n+m)) the     { thememset (k,0,sizeof(k)); theMemset (Head,-1,sizeof(head)); +memset (s),0,sizeof(s)); -  the          while(m--)Bayi         { thescanf"%s%d%d", CH, &a, &b); the             if(ch[0] =='I') -             { -                  for(inti =0; I <3; i++) the                 { the                     GetI2*a,2*b+1); the                     GetI2*b,2*a+1); the                 } -             } the             Else Get(ch[0]-'X',2*a+1,2*b); the         } the          for(inti =1; I <= N; i++)94              for(intj =0; J <3; J + +)Get(J,2(In2*i+1); the  theprintf"Case %d:", tm++); the         BOOLp =0;98          for(inti =0; I <3; i++) About         { -             if(!Tsort (i))101             {102printf"impossible\n\n");103p =1;104                  Break; the             }106 107         }108         if(p)Continue;109  theprintf"possible\n");111          for(inti =2; I <=2*n+1; i++) the         {113              for(intj =0; J <3; J + +) the             { theprintf"%d", S[i].val[j]); the                 if(i%2==0|| J <2) printf (" ");117                 Elseprintf"\ n");118             }119         } -printf"\ n");121     }122     return 0;123}

Code posture and the big God than still very frustrated ... Need to continue to work!

hdu3231 (triple topology sort)

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.