# hdu6062RXD and logic gates多校题 构造

（话说这种题一眼看过去怎么跟题答一样）

（这一位的输入，两个子问题）进行一次操作

 1 #include <bits/stdc++.h>
2 #define I n+2
3 #define O n+3
4 using namespace std;
5 int n,N,E,sum;
6 int a[20000],b[20000],c[20000];
7 bool rule[20000],fir[20000];
8 void addedge(int x,int y,int z)
9 {
10     a[++E]=x;b[E]=y;c[E]=z;
11 }
12 void work(int st,int en,int len,int pos)
13 {
14     if(len==1)
15     {
17         else
19         else
21         else
23         return;
24     }
25     int mid=st+en>>1;
26     work(st,mid,len-1,pos);
27     for(int i=0;i<=mid-st;i++)
28         rule[mid+1+i]^=rule[st+i];
29     int POS=++N;
30     work(mid+1,en,len-1,POS);
32     for(int i=0;i<=mid-st;i++)
33         rule[mid+1+i]^=rule[st+i];
34 }
35 int main()
36 {
37     while(~scanf("%d",&n))
38     {
39         N=n+3;E=0;
40         fir[I]=1;fir[O]=0;
41         for(int i=1;i<=1<<n;i++)
42         {
43             char ch;
44             for(ch=getchar();!isdigit(ch);ch=getchar());
45             for(sum=0;isdigit(ch);ch=getchar())
46                 sum=sum*2+ch-'0';
47             scanf("%d",&rule[sum]);
48         }
49         work(0,(1<<n)-1,n,n+1);
50         printf("%d\n",fir[n+1]);
51         printf("%d\n",N-n-1);
52         for(int i=n+2;i<=N;i++)
53             printf("%d\n",fir[i]);
54         printf("%d\n",E);
55         for(int i=1;i<=E;i++)
56             printf("%d %d %d\n",a[i],b[i],c[i]);
57     }
58     return 0;
59 } 

posted @ 2017-08-01 19:18  汪立超  阅读(301)  评论(0编辑  收藏