讨论 / 做人要厚道,自己有脑子
lc123456 2009-06-30 05:00:00
点我顶贴 收藏 删除
无敌的位运算,甚至不需要在算法上作任何优化,就能全部AC

以下是程序清单:

var i,j,count,n:longint;

==============================================================

function check(i,sum:longint):boolean;

var a,b,c,j,w,t:longint;

begin

w:=sum;

t:=0;

for j:=1 to i do begin t:=t shl 1+(w and 1);w:=w shr 1;end;

for j:=1 to i div 3 do

begin w:=t;

   a:=w and (1 shl j-1);

   w:=w shr j;

   b:=w and (1 shl j-1);

   w:=w shr j;

   c:=w and (1 shl j-1);

   if (a=b)and(a=c) then exit(false);

end;

exit(true);

end;

=============================================================

procedure search(i,sum:longint);

begin

if i>n then begin inc(count);exit;end;

if check(i,sum) then search(i+1,sum);

if check(i,sum+1 shl (i-1)) then search(i+1,sum+1 shl (i-1));

end;

=============================================================

begin

readln(n);

if n=1 then begin writeln(2);halt;end;

search(2,0);

writeln(2*count);

end.

===============做人要厚道,自己有脑子============================

#1 xxwzy@2009-05-09 04:52:00
回复 删除
速度是有了,

但n>=35就爆longint了

shr爆了

#2 xxwzy@2009-05-09 04:56:00
回复 删除
哦,貌似不是爆 longint…………

反正爆了

#3 wywzxxz@2009-06-30 04:23:00
回复 删除
有脑子的白痴先生……本人帮你改不爆范围以后发现你建立在非常快速位运算的算法竟然还没有我的建立在非常非常慢的字符串上的快,特此ORZ
#4 king13@2009-06-30 05:00:00
回复 删除
你有脑子,的确,而且很大,是去山西装煤炭的!!!
查看更多回复
提交回复