-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.cpp
More file actions
49 lines (49 loc) · 796 Bytes
/
task2.cpp
File metadata and controls
49 lines (49 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
using namespace std;
int BST[10000];
int n = 1000;
int dfs(int cur)
{
if(BST[cur] == 0)
return 0;
int lson = cur * 2 + 1, rson = cur * 2 + 2;
if(BST[rson] != 0)
dfs(rson);
cout<<BST[cur]<<" ";
if(BST[rson] != 0)
dfs(lson);
return 0;
}
void build(int n, int m)
{
if(BST[n] == m)
return;
if(BST[n] == 0)
{
BST[n] = m;
return;
}
if(m < BST[n])
{
build(2*n+1, m);
}
else
{
build(2*n+2, m);
}
return;
}
int main()
{
build(0, 500);
for (int i = 250; i > 2; i/=2)
{
for(int j = i; j < n; j += i)
build(0, j);
}
for(int i = 0; i < 1000; i++)
cout<<BST[i]<<" ";
cout<<endl;
dfs(0);
return 0;
}