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;
begin
    for i:=1 to n do b[i]:=1;
end;
function pd:boolean;//判断是不是解
var i:longint;
begin
  for i:=1 to n do if a[i]<>2 then
  begin
    if a[i]<>b[i] then exit(false);
  end;
  exit(true);
end;
begin
  read(n);
  read(c);
  for i:=1 to n do a[i]:=2;
  while m<>-1 do
  begin
    read(m);
    a[m]:=1;
  end;
  m:=0;
  while m<>-1 do
  begin
    read(m);
    a[m]:=0;
  end;
  //枚举
  for i1:=0 to 1 do
  for i2:=0 to 1 do
  for i3:=0 to 1 do
  for i4:=0 to 1 do
  begin
  if ((i1+i2+i3+i4) mod 2=c mod 2) and (c>=i1+i2+i3+i4) then
    begin
   new;
   if i1=1 then//如果第一个打开
   begin
     for i:=1 to n do b[i]:=(b[i]+1) mod 2;
   end;
   if i2=1 then//如果第二个打开
   begin
     for i:=1 to n do if i mod 2=1 then b[i]:=(b[i]+1) mod 2;
   end;
   if i3=1 then//如果第三个打开
   begin
     for i:=1 to n do if i mod 2=0 then b[i]:=(b[i]+1) mod 2;
   end;
   if i4=1 then//4....
   begin
     for i:=0 to n div 3+1 do b[i*3+1]:=(b[i*3+1]+1) mod 2;
   end;
   if pd then
   begin
     inc(sum);
     for i:=1 to n do
     s[sum]:=s[sum]+chr(b[i]+48);
   end;
   end;
  end;
  for i:=1 to sum-1 do//排序
  for j:=1 to sum-i do
  if s[j]>s[j+1] then
  begin
    s[0]:=s[j];
    s[j]:=s[j+1];
    s[j+1]:=s[0];
  end;
  if sum=0 then writeln('IMPOSSIBLE');//无解呀QAQ
  for i:=1 to sum do writeln(s[i]);//有解呀QAQ
end.//不难呀QwQ

这题不是很难呀,主要考的是细心

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值