Usaco 2.2 Party Lamps lantern (lamps)

Source: Internet
Author: User

Title Description

at IOI98 's festive party, we had n (10<=n<=100) colored lights, each numbered from 1 to N.
These lights are connected to four buttons:

    • Button 1: When this button is pressed, all lights will be changed: the light on the original is turned off, and the lamp that was originally closed is lit.

    • Button 2: When this button is pressed, all the odd number lights will be changed.

    • Button 3: When this button is pressed, the lights of all even numbers will be changed.

    • Button 4: When this button is pressed, all the serial numbers are changed to 3*k+1 (k>=0) lights. For example: 1,4,7 ...

a counter C records the number of times the button was pressed.
When the party starts, all the lights are on, and the counter C is 0.
You will get the value on counter C (0<=c<=10000) and the status of all lights after several operations. Write a program to find out the last possible status of all lights in accordance with the given information, and no repetition.

Inputno lantern will appear two times in the input.
First line: N.
Second line: c the last displayed value.
Third line: the last lighted lamp, separated by a space, ended with a-1.
Line Fourth: the last closed lamp, separated by a space, to 1 for the end.
Output

each line is the last possible state of all lights (No duplicates). Each line has n characters, the 1th character represents the No. 1th lamp, and the last character represents the n number lamp. 0 indicates off, 1 indicates on. These rows must be arranged from small to large (as binary numbers).
If there is no possible state, output one line of ' impossible '.

Input/Output sampleCopy
101-17-1
Copy
000000000001010101010110110110
Tips

In this example, there are 10 lights, and only 1 buttons are pressed. The last number 7th lights are off.

In this example, there are three possible states:

* All the lights are off *
* 1,4,7,10 lights off, 2,3,5,6,8,9 on.
* 1,3,5,7,9 light off, 2, 4, 6, 8, 10 on.

   

when I started to do it, I had no idea how to hit DFS and see Nocow ("Nocow") and found a constant table. I'm sure he's going to tell me better than I said, so give me a links However, I would like to say that my understanding of the fact that you can see that every 6 cycles why? That is, GCD (1,2,2,3) followed by 2 Press 3 = press 1 Press 1 Press 2 = Press 3 Press 1 Press 3 = Press 2 press 1 Press 2 Press 3 = Do not press .... (omitted below) after this, all the cases are saved with a constant table and then the last traversal is given to him to determine whether to press or off the light and then to the constant table to see if it matches and then there are some boundaries to consider, and then I this code in Usaco can be a, but Yzoi always have a point to get through (What pit daddy data ......)

There is a picture for proof:

The code is as follows:

/*id:laphetsprog:lampslang:c++*/#include <iostream> #include <cstdio> #include <cstring>using  namespace Std;const int maxn=10000+10;int n,c,x,tmp;int data[maxn];int cnt1,cnt2; int light[9][7]={0,0,0,0,0,0,0, 0,0,0,0,0,0,0,//push 1 0,0,0,1,1,1,0,//push 1 and 4 0,0,1,0,1,0,1,//pus H 3 0,0,1,1,0,1,1,//push 1 and 4 0,1,0,0,1,0,0,//push 4 0,1,0,1,0,1,0,//push 2 0,1,1,0,0,0,1,//push 2 and 4 0,1,1,1,1,1,1,//no push};  int minmum[9]={0,1,2,1,2,1,1,2,0};     int main () {//Freopen ("1.sb", "R", stdin), Freopen ("Lamps.in", "R", stdin), Freopen ("Lamps.out", "w", stdout);    cin>>n>>c;    memset (data,-1,sizeof (data));    while (Cin>>x&&x!=-1) data[x]=1,cnt1++;    while (Cin>>x&&x!=-1) data[x]=0,cnt2++;     if (c==0) {if (cnt1==n) {while (n--) Cout<<0;cout<<endl;return 0;}    if (cnt2==0) {while (n--) cout<<1;    cout<<endl; return 0;} if (cnt2!=0) {cout<< "ImpossibLE "<<endl; return 0;}}    if (cnt1==n) {while (n--) Cout<<0;cout<<endl;return 0;}    BOOL Flag1=false;        for (int i=1;i<=8;i++) {bool flag2=true;            for (int j=1;j<=n;j++) {if (data[j]==-1) continue;            tmp=j%6;            if (tmp==0) tmp=6;                if (Data[j]!=light[i][tmp]) {flag2=false;            Break            }} if (Flag2==true&&c>minmum[i]) {//cout<<1<<endl;            Flag1=true;                for (int j=1;j<=n;j++) {tmp=j%6;                if (tmp==0) tmp=6;            cout<<light[i][tmp];        } cout<<endl;      }} if (Flag1==false) cout<< "Impossible" <<endl; return 0;}


Usaco 2.2 Party Lamps lantern (lamps)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.