1 条题解
-
0
C++ :
#include <cstdio> #include <cstring> using namespace std ; char data[1026<<1] ; char change( char a , char b ) { if( a != b )return 'F' ; if( a == '0' ) return 'B' ; if( a == '1' ) return 'I' ; return a ; } char dfs( int deep , int idx ) { char c ; if( deep == 0 ) c = change(data[idx],data[idx]) ; else c = change( dfs(deep-1 , idx*2+1) , dfs( deep-1 , idx*2) ) ;//参数从右边往左边传 printf("%c" , c ) ; return c ; } int main() { int deep ; scanf("%d" , &deep ) ; scanf("%s" , data + (1<<deep) ) ; dfs( deep , 1 ) ; }
Pascal :
var f:array[1..1024] of char; i,k,n:integer; c:char; function lastorder(i,j,n:integer):char; var lc,rc:char; begin if n=0 then lastorder:=f[ i ] else begin lc:=lastorder(i,(i+j) div 2,n-1); write(lc); rc:=lastorder((i+j) div 2+1,j,n-1); write(rc); if lc=rc then lastorder:=lc else lastorder:='F'; end; end; begin { assign(input,'fbi.in'); reset(input);} readln(n); k:=1; for i:=1 to n do k:=k*2; for i:=1 to k do begin read(c); if c='0' then f[ i ]:='B' else f[ i ]:='I' end; readln; //close(input); //assign(output,'fbi.out'); //rewrite(output); writeln(lastorder(1,k,n)); //close(output); end.
Java :
import java.util.Scanner; public class Main { /** * @param args * @throws IOException * @throws NumberFormatException */ static int s,t,A,B; public static void main(String[] args){ // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int N=in.nextInt(); String s=in.next(); fbi(s); } public static char fbi(String s){ if (s.length()==1){ if (s.charAt(0)=='0'){ System.out.print('B'); return 'B'; }else { System.out.print('I'); return 'I'; } }else { char left=fbi(s.substring(0,s.length()/2)); char right=fbi(s.substring(s.length()/2)); if (left=='B'&&right=='B'){ System.out.print('B'); return 'B'; }else if (left=='I'&&right=='I'){ System.out.print('I'); return 'I'; }else { System.out.print('F'); return 'F'; } } } }
- 1
信息
- ID
- 666
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者