[cf461D]Appleman and Complicated Task

Assume that the rectangles of aij , then there are A (I, J) = A (I-. 1, J-. 1) ^ A (I-. 1, J +. 1) ^ A (I-2, J) , constantly recursion can found A (I, J) = A (. 1,. 1 + X-Y) ^ A (. 1,. 3 + X-Y) ...... ^ A ^ (. 1,. 1-X + Y) .

So, the first line processing and the prefix, Si = S (i-2) ^ A (. 1, i) , i.e., given two numbers S XOR, just each split point to point i and i ' , then if Sj = 0 ^ Si , and is connected on the collector side check (i, J) (i', J ') , or even the (i, J ') (i ', J) , only the last judgment i and i ' if connected, that is connected to 0 (this can be understood as i denotes i on is . 1 , i ' represents i a is 0 ).

Finally, there are many statistics block Unicom, with S a, the answer is 2 ^ {$ (. 4-S) / 2} $ (if there is no constraint, the answer is $ 2 ^ {n} = 2 ^ {2n + 4-4 ) / 2 $ )

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,m,x,y,ans,f[200005];
 4 char s[11];
 5 int find(int k){
 6     if (k==f[k])return k;
 7     return f[k]=find(f[k]);
 8 }
 9 void add(int x,int y){
10     if (find(x)!=find(y))f[find(x)]=find(y);
11 }
12 int main(){
13     scanf("%d%d",&n,&m);
14     for(int i=1;i<=2*n+3;i++)f[i]=i;
15     for(int i=1;i<=m;i++){
16         scanf("%d%d%s",&x,&y,s);
17         x-=y;
18         y=min(x+2*y,2*n-x-2*y+2);
19         x=max(x,-x);
20         if (s[0]=='x'){
21             add(2*y,2*x);
22             add(2*y+1,2*x+1);
23         }
24         else{
25             add(2*y+1,2*x);
26             add(2*x+1,2*y);
27         }
28     }
29     for(int i=0;i<=n+1;i++)
30         if (find(2*i)==find(2*i+1)){
31             printf("0");
32             return 0;
33         }
34     int s=0;
35     for(int i=0;i<=2*n+3;i++)s+=(find(i)==i);
36     s=s/2-2;
37     ans=1;
38     for(int i=1;i<=s;i++)ans=ans*2%1000000007;
39     printf("%d",ans);
40 }
View Code

 

Guess you like

Origin www.cnblogs.com/PYWBKTDA/p/11254585.html