ZOJ 3209 Treasure Map Precision Overlay

Source: Internet
Author: User

Topic links

Accurate coverage of the template problem, each of the grid as a column can be.

s forget to initialize the tle n times, cry out in the toilet ...

1#include <bits/stdc++.h>2 using namespacestd;3 #definePB (x) push_back (x)4 #definell Long Long5 #defineMK (x, y) make_pair (x, y)6 #defineLson L, M, rt<<17 #defineMem (a) memset (a, 0, sizeof (a))8 #defineRson m+1, R, rt<<1|19 #defineMem1 (a) memset (a,-1, sizeof (a))Ten #defineMEM2 (a) memset (a, 0x3f, sizeof (a)) One #defineRep (I, A, n) for (int i = A; i<n; i++) A #defineull unsigned long Long -typedef pair<int,int>PLL; - Const DoublePI = ACOs (-1.0); the Const DoubleEPS = 1e-8; - Const intMoD = 1e9+7; - Const intINF =1061109567; - Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} }; + Const intMAXN =10205; - Const intMaxnode =520005; + structDLX { A     intL[maxnode], R[maxnode], U[maxnode], D[maxnode], Row[maxnode], Col[maxnode]; at     intS[MAXN], H[MAXN], deep, SZ, N, M, num; -     voidRemoveintc) { -L[R[C]] =L[c]; -R[L[C]] =R[c]; -          for(inti = d[c]; I!=c; i =D[i]) -              for(intj = R[i]; J!=i; j =R[j]) { inU[D[J]] =U[j]; -D[U[J]] =D[j]; tos[col[j]]--; +             } -     } the     voidResumeintc) { *          for(inti = u[c]; I!=c; i =U[i]) $              for(intj = L[i]; J!=i; j =L[j]) {Panax Notoginsengs[col[j]]++; -D[U[J]] =J; theU[D[J]] =J; +             } AR[L[C]] =C; theL[R[C]] =C; +     } -     voidDfsintd) { $         if(d>=Deep ) $             return ; -         if(r[0] ==0) { -Deep =min (d, deep); the             return ; -         }Wuyi         intc = r[0]; the          for(inti = r[0]; i!=0; i =R[i]) -             if(s[c]>S[i]) Wuc =i; - Remove (c); About          for(inti = d[c]; I!=c; i =D[i]) { $              for(intj = R[i]; J!=i; j =R[j]) - Remove (col[j]); -DFS (d+1); -              for(intj = L[i]; J!=i; j =L[j]) A Resume (col[j]); +         } the resume (c); -         return ; $     } the     voidAddintRintc) { thesz++; theCOL[SZ] =C; thes[c]++; -U[SZ] =U[c]; inD[SZ] =C; theD[U[C]] =sz; theU[C] =sz; About         if(~H[r]) { theR[SZ] =H[r]; theL[SZ] =L[h[r]]; theL[R[SZ]] =sz; +R[L[SZ]] =sz; -}Else { theH[R] = L[sz] = R[sz] =sz;Bayi         } the     } the     voidinit () { - mem1 (H); -          for(inti =0; i<=n; i++) { theR[i] = i+1; theL[i] = i1; theD[i] = U[i] =i; the         } -R[n] =0; thel[0] =N; the Mem (S); theSZ =N;94Deep =inf; the     } the     voidsolve () { thescanf"%d%d%d", &n, &m, &num);98N *=m; About init (); -         intx1, y1, x2, y2;101         intCNT =1;102          while(num--) {103scanf"%d%d%d%d", &x1, &y1, &AMP;X2, &y2);104              for(inti = x1+1; i<=x2; i++) { the                  for(intj = y1+1; j<=y2; J + +) {106Add (CNT, (I-1) *m+j);107                 }108             }109cnt++; the         }111Dfs0); the         if(Deep = =inf) {113Puts"-1"); the}Else { theprintf"%d\n", deep); the         }117     }118 }DLX;119 intMain () - {121     intT;122Cin>>T;123      while(t--) {124 dlx.solve (); the     }126}

ZOJ 3209 Treasure Map Precision Overlay

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.