【搜索】P1468 派對燈 Party Lamps

P1468 派對燈 Party Lamps

咱們來分析一下對燈的操做ios

1.對全部燈的,這時吧全部燈當作一個總體c++

2.奇偶數的操做,這時能夠把每兩個數當作一個循環節ide

3.對3X+ 1的操做,這時能夠把每三個數當作一個循環節ui

顯而易見的,咱們把序列當作6個一組的循環節,便能模擬整個序列。spa

用筆畫一下,咱們發現將這個含六個元素的序列進行變換最終只會有八種結果,那麼咱們只須要判斷一下最後這八種結果code

最後是否符合題意要求就好了(至於他是怎麼變換的咱們不用管)blog

以上就是在題解區找到的解釋,其實說得很好,但願原做者 fastle 見諒。ci

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N = 1e3+10;
 4 int One[N],Zero[N],cnt1,cnt2;
 5 int n,C;
 6 int a[N][16];
 7 string S[100];
 8 char s[N];
 9 void Init(){
10     for(int i=0;i<N;i++){
11         for(int j=0;j<=15;j++){
12             a[i][j] = 1;
13         }
14     }
15 }
16 inline bool check( int No ){
17     int cnt = 0 ;
18     for(int i=0;i<4;i++){
19         if( (No & (1<<i)) == (1<<i) )
20             cnt++;
21     }
22     bool F = (cnt<=C) ;
23     for(int i=0;i<cnt1;i++){
24         if( a[One[i]][No] != 1 ) F = false;
25     }
26     for(int i=0;i<cnt2;i++){
27         if( a[Zero[i]][No] != 0 ) F = false;
28     }
29     return F;
30 }
31 int main()
32 {
33     ios_base :: sync_with_stdio(0);
34     cin.tie(NULL) , cout.tie(NULL);
35     Init();
36     cin>>n>>C;
37     while( cin>>One[cnt1++] ){
38         if(One[cnt1-1]==-1){
39             cnt1--;     break;
40         }
41     }
42     while( cin>>Zero[cnt2++] ){
43         if(Zero[cnt2-1]==-1){
44             cnt2--;     break;
45         }
46     }
47     /*
48     for(int i=0;i<cnt1;i++){
49         printf("%d%c",One[i],i==cnt1-1?'\n':' ');
50     }
51     for(int i=0;i<cnt2;i++){
52         printf("%d%c",Zero[i],i==cnt2-1?'\n':' ');
53     }
54     */
55     for(int i=0;i<=15;i++){
56         if( i & 1 ){
57             for(int j=1;j<=n;j++){
58                 a[j][i] = a[j][i] ^ 1 ;
59             }
60         }
61         if( (i>>1) & 1 ){
62             for(int j=1;j<=n;j+=2){
63                 a[j][i] = a[j][i] ^ 1 ;
64             }
65         }
66         if( (i>>2) & 1 ){
67             for(int j=2;j<=n;j+=2){
68                 a[j][i] = a[j][i] ^ 1 ;
69             }
70         }
71         if( (i>>3) & 1 ){
72             for(int j=1;j<=n;j+=3){
73                 a[j][i] = a[j][i] ^ 1 ;
74             }
75         }
76     }
77     int cnt = 0 ;
78 
79     for(int j=0;j<=15;j++){
80         if( check(j) ) {
81             for(int i = 1 ; i <= n; i++){
82                 s[i-1] = a[i][j] + '0';
83             }
84             s[n] = '\0';
85             S[cnt++] = s;
86         }
87     }
88     if( cnt == 0 ){
89         cout<<"IMPOSSIBLE"<<endl;
90     }else{
91         sort(S,S+cnt);
92         cnt = unique(S,S+cnt)-S;
93         for(int i = 0 ; i < cnt ; i++ ){
94             cout<<S[i]<<endl;
95         }
96     }
97     return 0;
98 }
View Code
相關文章
相關標籤/搜索