讨论 / 为什么总是wa后两个点?
xiaokeke 2013-02-19 03:34:00
点我顶贴 收藏 删除
我们几个一起写的程序,为什么都是wa的最后两个点呢?
#1 woshiniba@2008-08-23 18:49:00
回复 删除
我也是

program rq021;

type

tree=record

ch:char;

num,p,l,r:longint;

end;

var

t:array [0..2049] of tree;

n,mi,i:longint;

s:string;

function two(i:longint):longint;

var

tt,f:longint;

begin

tt:=1;

for f:=1 to i do

tt:=tt*2;

two:=tt;

end;

procedure find(i:longint; s:string);

var

z,o:longint;

s1,s2:string;

begin

z:=pos(’0’,s);

o:=pos(’1’,s);

if (z>0)and(o=0) then t[i].ch:=’B’;

if (z=0)and(o>0) then t[i].ch:=’I’;

if (z>0)and(o>0) then t[i].ch:=’F’;

if length(s)>1 then begin

s1:=copy(s,1,length(s) div 2);

s2:=copy(s,length(s) div 2+1,length(s) div 2);

if t[i].l<>0 then find(t[i].l,s1);

if t[i].r<>0 then find(t[i].r,s2);

end;

write(t[i].ch);

end;

begin

readln(n);

readln(s);

mi:=two(n+1);

for i:=1 to mi do

begin

t[i].num:=i;

t[i].p:=i div 2;

if 2*i<mi then t[i].l:=2*i;

if 2*i+1<mi then t[i].r:=2*i+1;

end;

find(1,s);

readln; readln;

end.

#2 jww521@2009-08-15 18:12:00
回复 删除
我的也是耶,为什么呢?

#include "stdio.h"

#include "stdlib.h"

struct node

{

char *s;

int ls;

int PD;

struct node *l;

struct node *r;

};

int n;

void BuiltTree(struct node *x)

{

if(x->ls/2==0)

return ;

else

{

struct node *p;

p=(struct node *)malloc(sizeof(struct node ));

p->ls=(x->ls)/2;

p->s=(char *)malloc(sizeof(char )*(p->ls+1));

p->l=NULL;

p->r=NULL;

int flag1=0,flag2=0;

for(int i=1;i<=p->ls;i++)

{

p->s[i]=x->s[i];

if(p->s[i]==’0’)

flag1=1;

else

flag2=1;

}

if(flag1==1)

{

if(flag2==1)

p->PD=3;

else

p->PD=1;

}

else

p->PD=2;

x->l=p;

BuiltTree(p);

p=(struct node *)malloc(sizeof(struct node ));

p->ls=(x->ls)/2;

p->s=(char *)malloc(sizeof(char )*(p->ls+1));

p->l=NULL;

p->r=NULL;

flag1=0;

flag2=0;

for(int i=1;i<=p->ls;i++)

{

p->s[i]=x->s[i+p->ls];

if(p->s[i]==’0’)

flag1=1;

else

flag2=1;

}

if(flag1==1)

{

if(flag2==1)

p->PD=3;

else

p->PD=1;

}

else

p->PD=2;

x->r=p;

BuiltTree(p);

}

}

void Print(struct node *t)

{

if(t==NULL)

return ;

else

{

Print(t->l);

Print(t->r);

if(t->PD==1)

printf("B");

else if(t->PD==2)

printf("I");

else

printf("F");

}

}

void Init()

{

struct node *a;

int flag1=0,flag2=0;

a=(struct node *)malloc(sizeof(struct node));

scanf("%d",&n);

a->ls=1;

a->s=(char *)malloc(sizeof(char )*(a->ls+1));

scanf("%s",a->s);

for(int i=1;i<=n;i++)

a->ls*=2;

for(int i=a->ls;i>0;i--)

{

a->s[i]=a->s[i-1];

if(a->s[i]==’0’)

flag1=1;

else

flag2=1;

}

if(flag1==1)

{

if(flag2==1)

a->PD=3;

else

a->PD=1;

}

else

a->PD=2;

a->l=NULL;

a->r=NULL;

BuiltTree(a);

Print(a);

}

int main()

{

Init();

getchar();

getchar();

return 0;

}

#3 L.Lawliet@2010-03-20 00:44:00
回复 删除
晕 怎么都wa最后两点 我是pascal 的 望神牛指教

program FBI;

const maxn=2048;

var a:array[0..maxn]of integer;

mark:array[0..maxn]of boolean;

total,n:integer;

i:integer;

procedure init;

var str:string;

k:integer;

i:integer;

begin

readln(str);

k:=0;

for i:=(total+1)div 2 to total do

begin

inc(k);

a[i]:=ord(str[k])-48;

mark[i]:=true;

end;

end;

function jian(i:integer):integer;

var x,y:integer;

begin

if mark[i] then exit(a[i]);

x:=jian(i*2);

y:=jian(i*2+1);

if (x<>y)or(x=2)or(y=2) then a[i]:=2

else

begin

if x=1 then a[i]:=1;

if x=0 then a[i]:=0;

end;

mark[i]:=true;

exit(a[i]);

end;

procedure back(i:integer);

begin

if i<=total then

begin

back(i*2);

back(i*2+1);

if a[i]=2 then write('F');

if a[i]=0 then write('B');

if a[i]=1 then write('I')

end;

end;

{main}

begin

fillchar(mark,sizeof(mark),false);

readln(n);

inc(n);

inc(total);

for i:=1 to n do

total:=total*2;

dec(total);

init;

// writeln(total);

jian(1);

//for i:=1 to total do writeln(a[i]);

back(1);

end.

#4 L.Lawliet@2010-03-21 05:54:00
回复 删除
哦 换ansistring

我另外有帖子 贴了源代码 大家可以参照

#5 lijiaming12340@2010-05-22 21:39:00
回复 删除
递归太烦了,不如用站加队列试试

#6 达达@2012-01-29 05:01:00
回复 删除
回复 地下室lijiaming12340 的帖子

Unaccepted

测评机: Xeost[5]

得分: 90分

提交日期: 2012-1-29 20:57:00

有效耗时: 1422毫秒

测试结果1: 通过本测试点|有效耗时156ms

测试结果2: 通过本测试点|有效耗时156ms

测试结果3: 通过本测试点|有效耗时157ms

测试结果4: 通过本测试点|有效耗时156ms

测试结果5: 通过本测试点|有效耗时156ms

测试结果6: 通过本测试点|有效耗时156ms

测试结果7: 通过本测试点|有效耗时157ms

测试结果8: 通过本测试点|有效耗时156ms

测试结果9: 通过本测试点|有效耗时172ms

测试结果10:

提交代码:

view sourceprint?

01.

var ss:ansistring;

02.

s:array[1..1000]of integer;

03.

i,j,w,n:longint;

04.

ch:char;

05.

procedure work(begi,en:longint);

06.

var sum,i,mid:longint;

07.

begin

08.

sum:=0;

09.

for i:=begi to en do sum:=sum+s[i];

10.

if sum mod (en-begi+1)<>0

11.

then ss:='F'+ss

12.

else

13.

if sum div (en-begi+1)=1

14.

then ss:='I'+ss

15.

else ss:='B'+ss;

16.

if en-begi<>0 then

17.

begin

18.

mid:=(begi+en-1)div 2;

19.

work(mid+1,en);

20.

work(begi,mid);

21.

end;

22.

end;

23.

begin

24.

readln(n);w:=1;for i:=1 to n do w:=w*2;

25.

for i:=1 to w do begin read(ch);s[i]:=ord(ch)-ord('0');end;

26.

ss:='';

27.

work(1,w);

28.

writeln(ss);

29.

end.

数组不够大

我WA了最后一个

字符串装不下

#7 desprado2@2012-01-30 19:44:00
回复 删除
题解不是有吗?(蛋我也过不了,不知道是否正确)

program rq21;

var n:longint;

function tree(l,r:longint):char;

var x:longint; y,z,c:char;

begin

if l=r then

begin

read(c);

if c='1' then begin write('I'); exit('I'); end;

write('B'); exit('B');

end;

x:=(l+r) shr 1;

y:=tree(l,x); z:=tree(x+1,r);

if y=z then tree:=y else tree:='F';

write(tree);

end;

begin

readln(n);

tree(1,1 shl n);

end.

#8 习新果@2013-02-19 03:34:00
回复 删除
回复 沙发woshiniba 的帖子

字符串要用 ansistring

#9 习新果@2013-02-19 03:34:00
回复 删除
回复 地毯L.Lawliet 的帖子

字符串要用 ansistring

查看更多回复
提交回复