1176 Party Lamps

来源:互联网 发布:关键词优化有什么用 编辑:程序博客网 时间:2024/05/17 03:09
Party Lamps
Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 772   Accepted: 263

Description
To brighten up the gala dinner of the IOI'98 we have a set of N coloured lamps numbered from
1 to N. The lamps are connected to four buttons:
button 1 -- when this button is pressed, all the lamps change their state: those that are ON are turned OFF and those that are OFF are turned ON.
button 2 -- changes the state of all the odd numbered lamps.
button 3 -- changes the state of all the even numbered lamps.
button 4 -- changes the state of the lamps whose number is of the form 3K+1 (with K >= 0), i.e., 1,4,7,...
There is a counter C which records the total number of button presses.
When the party starts, all the lamps are ON and the counter C is set to zero.

You are given the value of counter C and information on the final state of some of the lamps. Write a program to determine all the possible final configurations of the N lamps that are consistent with the given information, without repetitions.

Input
Your program is to read from standard input. The input contains four lines, describing the number N of lamps available, the number C of button presses, and the state of some of the lamps in the final configuration.
The first line contains the number N and the second line the final value of counter C. The third line lists the lamp numbers you are informed to be ON in the final configuration, separated by one space and terminated by the integer -1. The fourth line lists the lamp numbers you are informed to be OFF in the final configuration, separated by one space and terminated by the integer -1.

The parameters N and C are constrained by:
10 <= N <= 100
1 <= C <= 10000
The number of lamps you are informed to be ON, in the final configuration, is less than or equal to 2.The number of lamps you are informed to be OFF, in the final configuration, is less than or equal to 2.

Output
Your program is to write to standard output. The output must contain all the possible final configurations (without repetitions) of all the lamps. There is at least one possible final configuration. Each possible configuration must be written on a different line. Each line has N characters, where the first character represents the state of lamp 1 and the last character represents the state of lamp N. A 0 (zero) stands for a lamp that is OFF, and a 1 (one) stands for a lamp that is ON. Configurations should be listed in binary ascending order.

Sample Input

 

Sample Output

 

Source
IOI 1998

 ****************************************************************************************

******************************************************************************************

  • Source Code
    #include <stdio.h>#include <string.h>char str[8][101]={ //一百盏灯用题目的四种条件变换,只能取下面八种情况,不知道是不是只有这八种情况?      //1 2 3 4   "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",//1 0 0 0 all   "0011100011100011100011100011100011100011100011100011100011100011100011100011100011100011100011100011",//0 0 1 1 !=1  "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",//0 1 0 0 all  "0110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110",//0 0 0 1 !=2  "1001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001",//1 0 0 1 !=1  "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",//0 0 1 0 all  "1100011100011100011100011100011100011100011100011100011100011100011100011100011100011100011100011100",//0 1 0 1 !=1  "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",//0 0 0 0 !=1  };int oo[8]={0,1,0,2,1,0,1,1}; //字符串次数的要求 int main(){  //  freopen("min5.txt","r",stdin);  //  freopen("mout5.txt","w",stdout);    int i,j,N,C,on,off,opt[8];    while(scanf("%d",&N)!=EOF){        scanf("%d",&C);        for(i=0;i<8;i++) opt[i]=1;  //假设全部符合条件         while(1){            scanf("%d",&on);            if(on==-1) break;            for(j=0;j<8;j++)                if(str[j][on-1]=='0') opt[j]=0; //不符合灯 "打开" 的条件         }        while(1){            scanf("%d",&off);            if(off==-1) break;            for(j=0;j<8;j++)                if(str[j][off-1]=='1') opt[j]=0; //不符合灯 "关闭" 的条件         }        for(i=0;i<8;i++){            if(opt[i]==1 && (C>oo[i] || (C==1&&i==3))){      //去掉不符合次数的条件                 for(j=0;j<N;j++) printf("%c",str[i][j]);                printf("/n");            }        }    }}
  • 000000000001010101010110110110

    101-17 -1
    原创粉丝点击