結果
問題 |
No.566 だいたい完全二分木
|
ユーザー |
|
提出日時 | 2017-10-04 00:24:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 1,386 ms |
コンパイル使用メモリ | 60,312 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 06:15:43 |
合計ジャッジ時間 | 1,197 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
#include <iostream> #include <cmath> using namespace std; int main(){ int K; cin >> K; int n_node = pow(2, K) - 1; int a[n_node]; // initialize for(int i=0; i< n_node; i++) a[i] = 0; int center = pow(2, K) / 2; a[0] = center; int left = center/ 2; int j=0; // Generate sequence of number which generates Complete Binary Tree. while(left >= 1){ j++; a[j] = left; int d = center; // common difference while(a[j] + d <= n_node){ a[j+1] = a[j] + d; j++; } center = left; left /= 2; } int i3=0,i2=0; bool t3=false, t2=false; // find where are 3 and 2 then swap them while(!t3 || !t2){ if(a[i2] == 2) t2=true; if(a[i3] == 3) t3=true; if(!t2) i2++; if(!t3) i3++; } a[i2] = 3; a[i3] = 2; for(int i=0; i<n_node; i++) cout << a[i] << endl; return 0; }