157 条题解
-
3
gss LV 8 @ 7 年前
#include<iostream>
using namespace std;
char a[1024 + 5];
int n;
char fun(char *s, int L){
if(L == 1){
if(*s == '0'){
cout<<'B';
return 'B';
}else{
cout<<'I';
return 'I';
}
}else{
char ch1, ch2;
ch1 = fun(s, L/2);
ch2 = fun(s + L/2, L/2);
if(ch1 == ch2){
cout<<ch1;
return ch1;
}else{
cout<<'F';
return 'F';
}
}
}
int main(){
//freopen("test.txt", "r", stdin);
cin>>n;
int i;
n = (1<<n);
cin>>a;
fun(a, n);
return 0;
} -
27 年前@
#不知为啥代码都那么长~~~~
cpp
#include<bits/stdc++.h>
using namespace std;
char a[1040];
int n;
char FBITREE(int l,int r){
if (l == r) if (a[l] == '1') return 'I'; else return 'B';
char fl = FBITREE(l,(l+r)/2); cout<<fl;
char fr = FBITREE((l+r)/2+1,r); cout<<fr;
if (fl == fr) return fl; else return 'F';
}
int main(){
cin>>n>>a;
int al = strlen(a);
cout<<FBITREE(0,al-1)<<endl;
}
-
15 年前@
python 递归
-
16 年前@
用了个栈数组,代码短了点
-
17 年前@
拼死写了个非递归
这是位运算用的最熟的一次 -
17 年前@
用数组建树,递归遍历。
-
17 年前@
比较懒,直接用的二分判断输出
-
17 年前@
一个ansistring加简单的搜索,一遍AC,题目较水。不要抄哦!
var
st:ansistring;
n:integer;
procedure try(n:integer; ss:ansistring);
var
i,j:integer;
s:char;
begin
i:=pos('0',ss);
j:=pos('1',ss);
if i=0 then s:='I' else
if j=0 then s:='B' else
s:='F';
if n>1 then
begin
n:=n div 2;
try(n,copy(ss,1,n));
try(n,copy(ss,n+1,n));
end;
write(s);
end;
begin
readln(n);
n:=1 shl n;
readln(st);
try(n,st);
writeln;
end. -
18 年前@
很笨的方法,递归建立树,子树用fbi直接替换,长度到1回溯
大牛勿喷。。。。。。。 -
05 年前@
-
06 年前@
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int l;
char s[2000];
char b[3000];
void search(int x)
{
if(x<l)
{
search(x*2);
search(x*2+1);
}
cout<<b[x];
}
int main()
{
int n,i;
cin>>n;
cin>>s;
l=strlen(s);
for(i=l;i<l*2;i++)
{
if(s[i-l]=='0')b[i]='B';
else b[i]='I';
}
for(i=l-1;i>=1;i--)
{
if(b[i*2]==b[i*2+1])b[i]=b[i*2];
else b[i]='F';
}
search(1);
return 0;
} -
07 年前@
有没有更优美的递归法?
#include<stdio.h>int n,a[1024],ans[2048],m,i,c;
int fbi(int x)
{
if(x=='I'+'I') return 'I';
if((x==('I'+'B'))||(x=='F'+'I'||x=='F'+'B'||x=='F'+'F')) return 70;
if(x=='B'+'B') return 'B';
}int answer(int s,int e,int i)
{
if(i==n)
{
c++;
return ans[c-1]=a[s]*('I'-'B')+'B';
}
else
{
int j=fbi(answer(s,s+(e-s)/2,i+1)+answer(s+(e-s)/2,e,i+1));
ans[c]=j;
c++;
return ans[c-1];
}
}int main()
{
scanf("%d",&n);
m=1;
for(i=0;i<n;i++) m*=2;
getchar();
for(i=0;i<m;i++) a[i]=getchar()-'0';
c=0;
answer(0,m,0);
for(i=0;i<c;i++) printf("%c",ans[i]);
return 0;
} -
07 年前@
恩。我看了一天的题目终于看懂了。。。。。。。这题目真的拗口啊 。。。。。看不懂题目还以为是啥子高级别的题目。。看懂后,突然感觉自己好蠢。。。。
-
08 年前@
-
08 年前@
-
08 年前@
-
08 年前@
-
08 年前@
-
08 年前@
-
08 年前@
###code
c++
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string str;
int n;
inline void dfs(int L,int R) {
if (L == R) { //走到叶节点
if (str[L] == '0') cout << 'B';
else cout << 'I';
return; //结束
}
int mid = (L+R)/2; //取中间值
dfs(L,mid); //左儿子
dfs(mid+1,R); //右儿子
bool zero = false,one = false;
for (int i = L;i <= R;i++)
if (str[i] == '1') one = true;
else if (str[i] == '0') zero = true;
if (one && zero) cout << 'F'; //既有0又有1
else if (one && !zero) cout << 'I'; //全1
else cout << 'B'; //全0
}
int main() {
ios :: sync_with_stdio(false);
cin >> n >> str;
dfs(0,str.length()-1); //后序遍历
return 0;
}