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.
#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;
}
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.
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了最后一个
字符串装不下
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.