noi水题,直接推出来每一位上取什么值才能取1
直接搞就可以了
var a,b:array[..] of longint;
x,n,i,j,k,t,m,ans:longint;
fl:boolean;
s:string;
ch:char; procedure doit(x:longint);
begin
fillchar(b,sizeof(b),);
m:=;
while x<> do
begin
inc(m);
b[m]:=x mod ;
x:=x shr ;
end;
end; begin
readln(n,k);
t:=;
for i:= to do
a[i]:=;
for i:= to n do
begin
s:='';
read(ch);
while ch<>' ' do
begin
s:=s+ch;
read(ch);
end;
readln(x);
doit(x);
if s='OR' then //表示这一位取什么值都能使ans这位上取1,-表示去什么都不可以,表示取1才可以,表示取0才可以
begin
for j:= to do
if b[j]= then a[j]:=;
end
else if s='AND' then
begin
for j:= to do
if b[j]= then a[j]:=-;
end
else begin
for j:= to do
if b[j]= then
begin
if a[j]=- then a[j]:=
else if a[j]= then a[j]:=-
else if a[j]= then a[j]:=
else if a[j]= then a[j]:=;
end;
end;
end;
doit(k);
ans:=;
fl:=false; //fl判断高位是否已经严格小于了
for i:= downto do
if fl then
begin
if a[i]<>- then
ans:=ans+ shl (i-);
end
else begin
if (b[i]=) and ((a[i]=) or (a[i]=)) then ans:=ans+ shl (i-);
if (b[i]=) then
begin
if (a[i]=) or (a[i]=) then
begin
fl:=true;
ans:=ans+ shl (i-);
end
else if a[i]=- then fl:=true
else ans:=ans+ shl (i-);
end;
end; writeln(ans);
end.