1 条题解

  • 0
    @ 2025-2-14 21:26:47

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int n, x;
    int a[1009], cnt;
    
    void dfs(int u) {
    	if (!a[u]) return;
    	
    	cout << a[u] << ' ';
    	dfs(u * 2);
    	dfs(u * 2 + 1);
    }
    
    int main() {
    	cin >> n;
    	while (n --) {
    		memset(a, 0, sizeof(a));
    		cnt = 0;
    		
    		while (cin >> x && x != -1) {
    			a[++ cnt] = x;
    		}
    		
    		cout << int(log2(cnt)) + 1 << ' ';
    		dfs(1);
    		cout << endl;
    	}
    
    	return 0;
    }
    
    • 1

    信息

    ID
    907
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者