Usaco Party Lamps

Source: Internet
Author: User

Test instructions is very simple, can see translation http://www.wzoi.org/usaco/13%5C104.asp

Because the same switch press two times equal to not press, so when C is greater than 4 o'clock, you can reduce C by 2, minus 4 or so, and then start the enumeration, after the analysis of the problem found can be used in a 6-bit binary to represent the first 6, and so on, after each 6 and the front of the same

0 and 1 XOR 0 unchanged, XOR 1 after 0 variable 0

The binary that is different from or to the current state is the state after the switch is pressed.

DFS will be able to solve

/*id:modengd1prog:lampslang:c++*/#include <iostream> #include <stdio.h> #include <memory.h>using namespace Std;int counter;int n;bool vis[1<<7];int on[64];int off[64];int op1=0x3f;int op2=0x15;//010101int op3= 0x2a;//101010int op4=0x24;//100100void slove (int c,int n,int deep,int lamp) {if (deep==c) {for (int i=0;on[i]!        =-1;i++) {if ((lamp& (1<< (on[i]-1)%6)) ==0) return; } for (int i=0;off[i]!=-1;i++) {if ((lamp& (1<< (off[i]-1)%6))!=0) Retu        Rn        } vis[lamp]=true;    return;    } slove (C,N,DEEP+1,LAMP^OP1);    Slove (C,N,DEEP+1,LAMP^OP2);    Slove (C,N,DEEP+1,LAMP^OP3); Slove (C,N,DEEP+1,LAMP^OP4);}    int main () {freopen ("lamps.in", "R", stdin);    Freopen ("Lamps.out", "w", stdout);    int c,n;    memset (vis,false,sizeof (VIS));    scanf ("%d", &n);    scanf ("%d", &c);  for (int i=0;scanf ("%d", &on[i]) &&on[i]!=-1;i++)      ;    for (int i=0;scanf ("%d", &off[i]) &&off[i]!=-1;i++);    while (c>4) c-=2;    Slove (c,n,0,0x3f);    BOOL Impossivle=true;            for (int i=0;i< (1<<6); i++) {if (Vis[i]) {impossivle=false;                for (int j=0;j<n;j++) if (i& (1<< (5-j%6))) cout<<1;            else cout<<0;        cout<<endl;    }} if (Impossivle) cout<< "Impossible" <<endl; return 0;}

  

Usaco Party 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.