Read in data before anything started.
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
// 'Natural count' is the name of the node when all the nodes in the tree is
|
||||
// alive. xxx_num denotes the count as the question described.
|
||||
|
||||
// SEE ALSO:
|
||||
// branch 04_02 has a correct and more elegant implementation.
|
||||
|
||||
int ans[200] = {0};
|
||||
long long dead_nodes_num[105] = {0};
|
||||
int total_dead_nodes = 0;
|
||||
@@ -38,7 +41,8 @@ SearchResult find_node(long long target, long long start_num, int next_dead_node
|
||||
}
|
||||
else {
|
||||
all_dead = false;
|
||||
long long total_spawned_after = spawned_node_max_num + upper_line[upper_line_iter].length * 2;
|
||||
long long total_spawned_after =
|
||||
spawned_node_max_num + upper_line[upper_line_iter].length * 2;
|
||||
while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
|
||||
next_dead_node_num_ptr < total_dead_nodes) {
|
||||
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) {
|
||||
@@ -123,26 +127,34 @@ SearchResult find_node(long long target, long long start_num, int next_dead_node
|
||||
int main() {
|
||||
scanf("%d %d", &total_dead_nodes, &total_target_nodes);
|
||||
for (int i = 0; i < total_dead_nodes; i++) {
|
||||
scanf("%d", &dead_nodes_num[i]);
|
||||
scanf("%lld", &dead_nodes_num[i]);
|
||||
}
|
||||
for (int i = 0; i < total_target_nodes; i++) {
|
||||
scanf("%lld", &target_nodes_num[i]);
|
||||
}
|
||||
if (dead_nodes_num[0] == 1) {
|
||||
for (int i = 0; i < total_target_nodes; i++) {
|
||||
if (target_nodes_num[i] == 1) {
|
||||
printf("1\n");
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
printf("0\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
long long current_target = 0;
|
||||
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
|
||||
for (int i = 0; i < total_target_nodes; i++) {
|
||||
scanf("%lld", ¤t_target);
|
||||
SearchResult result = find_node(current_target, 2, 0, &firstline, 1, 2);
|
||||
SearchResult result = find_node(target_nodes_num[i], 2, 0, &firstline, 1, 2);
|
||||
if (result.count_in_father_line == -1) {
|
||||
printf("0\n");
|
||||
}
|
||||
else {
|
||||
printf("1 ");
|
||||
for (int j = result.next_ans_pos - 1; j >= 0; j--) {
|
||||
printf("%d ", ans[j]);
|
||||
printf("%lld ", ans[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user