1 条题解
-
0
C++ :
#include<iostream> #include<cmath> using namespace std; int flag[70][70]; int main() { int i,j,k,n; cin>>n; int p=pow(2,n); for (j=1;j<=p-1;j++) { cout<<"<"<<j<<">"; int a[70]={0},cur=1,last; for (cur=1;cur<=p;cur++) { if (cur&1) { for (i=1;i<=p;i++) if (a[i]==0) { cout<<i<<"-";a[i]=1;last=i;break; } } else { for(i=1;i<=p;i++) if (a[i]==0 && flag[last][i]==0) { if (cur!=p)cout<<i<<","; else cout<<i; a[i]=1; flag[last][i]=1; break; } } } cout<<endl; } return 0; }
Pascal :
var i,j,k,m,n,half,s:integer; a:array [1..64,1..64] of integer; b:array[1..64]of boolean; begin readln(m); n:=1; for i:=1 to m do n:=n*2; k:=1;a[1,1]:=1;half:=1; while k<=m do begin for i:=1 to half do for j:=1 to half do a[i,j+half]:=a[i,j]+half; for i:=1 to half do for j:=1 to half do begin a[i+half,j]:=a[i,j+half]; a[i+half,j+half]:=a[i,j]; end; half:=half*2; k:=k+1; end; for i:=2 to n do begin write('<',i-1,'>'); fillchar(b,sizeof(b),true); s:=0; for j:=1 to n do if (b[j]) then begin write(j,'-',a[j,i]); inc(s); b[j]:=false; b[a[j,i]]:=false; if s<>n div 2 then write(','); end; writeln; end; end.
- 1
信息
- ID
- 181
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者