本文主要是介绍P1468 派对灯,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
暴力,不可能,肯定炸…怎么办呀,发现同一个按钮按两次就相当于没按QAQ
var i,j,k:longint;i1,i2,i3,i4:longint;m,n,c:longint;a:array[-1..1000]of longint;b:array[0..1000]of longint;s:array[0..1000]of string;sum:longint;
procedure new;//还原呀QAQ
var i:longint;
beginfor i:=1 to n do b[i]:=1;
end;
function pd:boolean;//判断是不是解
var i:longint;
beginfor i:=1 to n do if a[i]<>2 thenbeginif a[i]<>b[i] then exit(false);end;exit(true);
end;
beginread(n);read(c);for i:=1 to n do a[i]:=2;while m<>-1 dobeginread(m);a[m]:=1;end;m:=0;while m<>-1 dobeginread(m);a[m]:=0;end;//枚举for i1:=0 to 1 dofor i2:=0 to 1 dofor i3:=0 to 1 dofor i4:=0 to 1 dobeginif ((i1+i2+i3+i4) mod 2=c mod 2) and (c>=i1+i2+i3+i4) thenbeginnew;if i1=1 then//如果第一个打开beginfor i:=1 to n do b[i]:=(b[i]+1) mod 2;end;if i2=1 then//如果第二个打开beginfor i:=1 to n do if i mod 2=1 then b[i]:=(b[i]+1) mod 2;end;if i3=1 then//如果第三个打开beginfor i:=1 to n do if i mod 2=0 then b[i]:=(b[i]+1) mod 2;end;if i4=1 then//4....beginfor i:=0 to n div 3+1 do b[i*3+1]:=(b[i*3+1]+1) mod 2;end;if pd thenbegininc(sum);for i:=1 to n dos[sum]:=s[sum]+chr(b[i]+48);end;end;end;for i:=1 to sum-1 do//排序for j:=1 to sum-i doif s[j]>s[j+1] thenbegins[0]:=s[j];s[j]:=s[j+1];s[j+1]:=s[0];end;if sum=0 then writeln('IMPOSSIBLE');//无解呀QAQfor i:=1 to sum do writeln(s[i]);//有解呀QAQ
end.//不难呀QwQ
这题不是很难呀,主要考的是细心
这篇关于P1468 派对灯的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!