0pts求调,全RE

P1087 [NOIP2004 普及组] FBI 树

char c=s[l]; 那里有问题
by typerxiaozhu @ 2023-08-14 19:03:09


@[typerxiaozhu](/user/807832) ???
by caotianhao @ 2023-08-14 19:04:38


@[caotianhao](/user/671925) 你init这个函数有问题啊,如果l为0,r为2不就死循环然后栈溢出了吗,init的二分得改一下。
by Guagua_ @ 2023-08-15 09:32:28


@[Guagua_](/user/297064) 所以怎么改(改了n遍还RE)
by caotianhao @ 2023-08-15 09:37:28


@[caotianhao](/user/671925) 把 int mid=(l+r)/2+1; 那行的+1去了,还有,我感觉调完以后还是会wa,你看看是哪里写错了。
by Guagua_ @ 2023-08-15 09:39:53


@[caotianhao](/user/671925) 哈哈,确实,全是wa
by Guagua_ @ 2023-08-15 09:40:31


@[Guagua_](/user/297064) 调完以后还RE
by caotianhao @ 2023-08-15 09:40:52


@[caotianhao](/user/671925) 对了,漏了一个,l==r的时候就不能再二分了,我不知道你的代码用的是什么方法,反正我是把init的第一行l>r改成l>=r就没re了,至于为什么会wa我再看看。
by Guagua_ @ 2023-08-15 09:45:03


@[caotianhao](/user/671925) ``` #include<bits/stdc++.h> using namespace std; #define ls(x) ((x)<<1) #define rs(x) ((x)<<1|1) int n,m,cnt; char s[2050]; char FBI(int l,int r){ char c=s[l]; for(int i=l+1;i<=r;i++){ if(s[i]!=c){ return 'F'; } } if(c=='1'){ return 'I'; }else{ return 'B'; } } char t[2050]; void init(int root,int l,int r){ t[root]=FBI(l,r); if(l==r) return; int mid=(l+r)/2; init(ls(root),l,mid); init(rs(root),mid+1,r); } void hou(int root,int l,int r){ int mid=l+r>>1; if(l!=r){ hou(ls(root),l,mid); hou(rs(root),mid+1,r); } cout<<t[root]; } int main(){ cin>>m>>(s+1); n=pow(2,m); init(1,1,n); hou(1,1,n); return 0; } ``` 改了一下你的代码,应该能过。
by 鱼跃于渊 @ 2023-08-15 10:16:39


@[caotianhao](/user/671925) 对不起,现在才调好。[this](https://www.luogu.com.cn/paste/a9zi9tzx)
by Guagua_ @ 2023-08-15 10:18:30


| 下一页