USACO 2.2 Party Lamps(乱搞)

   操作次数很多,灯泡也比较多,但是灯泡其实只有4个集合,4种操作,操作2次等于没有改变,所以枚举就行了,最后输出字典序搓了,写了个冒泡。。。

  

  1 /*
  2  ID: cuizhe
  3  LANG: C++
  4  TASK: lamps
  5 */
  6 #include cstdio
  7 #include cstring
  8 #include cmath
  9 #include algorithm
 10 using namespace std;
 11 int aim[201],o[201],n,p[1001][201];
 12 int judge()
 13 {
 14     int i;
 15     for(i = 1;i = n;i ++)
 16     {
 17         if(aim[i] != -1)
 18         {
 19             if(o[i] != aim[i])
 20             return 0;
 21         }
 22     }
 23     return 1;
 24 }
 25 int cmp(int x,int y)
 26 {
 27     int i;
 28     for(i = 1;i = n;i ++)
 29     {
 30         if(p[x][i]  p[y][i])
 31         return 1;
 32         else if(p[y][i]  p[x][i])
 33         return 0;
 34     }
 35     return 0;
 36 }
 37 void swap(int x,int y)
 38 {
 39     int key[201],i;
 40     for(i = 1;i = n;i ++)
 41     key[i] = p[x][i];
 42     for(i = 1;i = n;i ++)
 43     p[x][i] = p[y][i];
 44     for(i = 1;i = n;i ++)
 45     p[y][i] = key[i];
 46 }
 47 int main()
 48 {
 49     int i,j,c,on,off,num,z,temp;
 50     freopen("lamps.in","r",stdin);
 51     freopen("lamps.out","w",stdout);
 52     memset(aim,-1,sizeof(aim));
 53     scanf("%d%d",n,c);
 54     z = 1;
 55     temp = 1;
 56     for(;;)
 57     {
 58         scanf("%d",on);
 59         if(on == -1) break;
 60         aim[on] = 1;
 61     }
 62     for(;;)
 63     {
 64         scanf("%d",off);
 65         if(off == -1) break;
 66         aim[off] = 0;
 67     }
 68     for(i = 0;i  (14);i ++)
 69     {
 70         num = 0;
 71         for(j = 1;j = n;j ++)
 72         o[j] = 1;
 73         if(i1)
 74         {
 75             memset(o,0,sizeof(o));
 76             num ++;
 77         }
 78         if(i2)
 79         {
 80             for(j = 1;j = n;j ++)
 81             {
 82                 if(j%2)
 83                 o[j] = (o[j]+1)%2;
 84             }
 85             num ++;
 86         }
 87         if(i4)
 88         {
 89             for(j = 1;j = n;j ++)
 90             {
 91                 if(j%2 == 0)
 92                 o[j] = (o[j]+1)%2;
 93             }
 94             num ++;
 95         }
 96         if(i8)
 97         {
 98             for(j = 1;j = n;j ++)
 99             {
100                 if(j%3 == 1)
101                 o[j] = (o[j]+1)%2;
102             }
103             num ++;
104         }
105         if(c = num(c-num)%2 == 0)
106         {
107             if(judge())
108             {
109                 z = 0;
110                 for(j = 1;j = n;j ++)
111                 p[temp][j] = o[j];
112                 temp ++;
113             }
114         }
115     }
116     temp --;
117     for(i = 1;i = temp-1;i ++)
118     {
119         for(j = 1;j = temp-i;j ++)
120         {
121             if(cmp(j,j+1))
122             {
123                 swap(j,j+1);
124             }
125         }
126     }
127     for(i = 1;i = temp;i ++)
128     {
129         for(j = 1;j = n;j ++)
130         printf("%d",p[i][j]);
131         printf("\n");
132     }
133     if(z) printf("IMPOSSIBLE\n");
134     return 0;
135 }

转载于:https://www.cnblogs.com/naix-x/archive/2012/11/10/2764179.html

最新回复(0)
/jishubdDpyVHpK4CV74KrGMZ6E888ZItn60mylI9qhTPOuDw_3D4858397
8 简首页