/* ID: lucien23prog: lampslang: c ++ * // ** note that if you press a button multiple of 2, it is equivalent to not pressing *. In fact, you only need to consider four buttons, whether or not each button has been effectively pressed once * use the enumeration method directly, there are only 2 ^ 4 = 16 cases in total * for each case, you need to know the number of effective times (that is, the number of buttons that have been pressed) that must meet * (c-valid times) % 2 = 0, so that other times can be regarded as invalid * And then verify whether various situations meet the requirements, output the required information in sequence */# include <iostream> # include <fstream> # include <vector> # include <algorithm> using namespace STD; bool comppro (int * strnum1, int * strnum2) {int I = 0; while (1) {If (St Rnum1 [I] <strnum2 [I]) return true; else if (strnum1 [I]> strnum2 [I]) return false; I ++;} int main () {ifstream infile ("lamps. in "); ofstream OUTFILE (" lamps. out "); If (! Infile |! OUTFILE) {cout <"file operation failure! "<Endl; Return-1 ;}int N, C; vector <int> veconlamps, vecofflamps; vector <int *> results; infile> N> C; int num; infile> num; while (num! =-1) {veconlamps. push_back (Num); infile> num;} infile> num; while (num! =-1) {vecofflamps. push_back (Num); infile> num;} int COUNT = 0; For (INT I = 0; I <16; I ++) {int * lamps = new int [N]; for (Int J = 0; j <n; j ++) {lamps [J] = 1;} int tempcnt = 0; for (Int J = 0; j <4; j ++) {int temp = 1 <j; If (temp & I) = temp) tempcnt ++ ;} if (C <tempcnt | (c-tempcnt) % 2! = 0) {Delete [] lamps; continue;} If (1 <0) & I) = (1 <0 )) {for (Int J = 0; j <n; j ++) {If (lamps [J] = 0) lamps [J] = 1; elselamps [J] = 0 ;}} if (1 <1) & I) = (1 <1) {for (Int J = 0; j <n; j ++) {If (J + 1) % 2 = 1) {If (lamps [J] = 0) lamps [J] = 1; elselamps [J] = 0 ;}} if (1 <2) & I) = (1 <2) {for (Int J = 0; j <n; j ++) {If (J + 1) % 2 = 0) {If (lamps [J] = 0) lamps [J] = 1; elselamps [J] = 0 ;}} if (1 <3 )& I) = (1 <3) {for (Int J = 0; j <n; j ++) {If (J + 1) % 3 = 1) {If (lamps [J] = 0) lamps [J] = 1; elselamps [J] = 0 ;}} bool flag = true; for (vector <int >:: iterator it = veconlamps. begin (); it! = Veconlamps. End (); It ++) {If (lamps [* It-1]! = 1) {flag = false; break;} If (! Flag) {Delete [] lamps; continue;} For (vector <int >:: iterator it = vecofflamps. Begin (); it! = Vecofflamps. End (); It ++) {If (lamps [* It-1]! = 0) {flag = false; break ;}} if (FLAG) {count ++; results. push_back (lamps);} else {Delete [] lamps ;}}if (COUNT = 0) {OUTFILE <"impossible" <Endl;} else {sort (results. begin (), results. end (), comppro); For (INT I = 0; I <count; I ++) {for (Int J = 0; j <n; j ++) {OUTFILE <Results [I] [J];} OUTFILE <Endl ;}} return 0 ;}