1176 Party Lamps

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");
                }
            }
        }
    }
    
    
  • 0000000000
    0101010101
    0110110110

    10
    1
    -1
    7 -1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcl119xxcl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值