-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDS_Quiz_3_tree.c
74 lines (66 loc) · 1.41 KB
/
DS_Quiz_3_tree.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
typedef struct tree{
int value;
int now;
// 1 左 2 右
struct tree* left;
struct tree* right;
} tree;
tree* createtree(tree* hi,int time,int value){
tree* temp = malloc(sizeof(tree));
temp->now=1;
(temp->value)=value;
//printf("%d",temp->value);
if (time>0){
time = time - 1;
temp->left = createtree(temp->left,time,2*(temp->value));
temp->right = createtree(temp->right,time,2*(temp->value)+1);
}
else {
return NULL;
}
return temp;
}
void printree(tree* a){
if (a->left != NULL){
printree(a->left);
}
printf("%d ",a->value);
if (a->right != NULL){
printree(a->right);
}
}
int fuckofball(tree* hi){
if (hi->left != NULL){
if ( hi->now == 1){
int x = fuckofball(hi->left);
hi->now = 2;
return x;
}
else{
int x = fuckofball(hi->right);
hi->now = 1;
return x;
}
}
else {
return hi->value;
}
}
int main(){
int x;
scanf("%d",&x);
while (x--){
tree* head = NULL;
int w = 0,ball = 0;
scanf("%d %d",&w,&ball);
head = createtree(head,w,1);
//printree(head);
int output = 0;
while (ball--){
output = fuckofball(head);
}
printf("%d\n",output);
}
}