Read in data before anything started.

This commit is contained in:
unlockable
2023-11-05 16:33:25 +08:00
parent b7b8af4811
commit c07330c8af

View File

@@ -4,6 +4,9 @@
// 'Natural count' is the name of the node when all the nodes in the tree is // '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. // 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}; int ans[200] = {0};
long long dead_nodes_num[105] = {0}; long long dead_nodes_num[105] = {0};
int total_dead_nodes = 0; int total_dead_nodes = 0;
@@ -16,7 +19,7 @@ struct SeveralContinuedDeadNode {
}; };
struct SearchResult { struct SearchResult {
int next_ans_pos; // pos in the ans[] array. int next_ans_pos; // pos in the ans[] array.
long long count_in_father_line; // natural count. long long count_in_father_line; // natural count.
}; };
@@ -38,7 +41,8 @@ SearchResult find_node(long long target, long long start_num, int next_dead_node
} }
else { else {
all_dead = false; 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 && while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
next_dead_node_num_ptr < total_dead_nodes) { next_dead_node_num_ptr < total_dead_nodes) {
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) { 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() { int main() {
scanf("%d %d", &total_dead_nodes, &total_target_nodes); scanf("%d %d", &total_dead_nodes, &total_target_nodes);
for (int i = 0; i < total_dead_nodes; i++) { 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) { if (dead_nodes_num[0] == 1) {
for (int i = 0; i < total_target_nodes; i++) { for (int i = 0; i < total_target_nodes; i++) {
printf("0\n"); if (target_nodes_num[i] == 1) {
printf("1\n");
continue;
}
else {
printf("0\n");
}
} }
return 0;
} }
else { else {
long long current_target = 0;
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1}; SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
for (int i = 0; i < total_target_nodes; i++) { for (int i = 0; i < total_target_nodes; i++) {
scanf("%lld", &current_target); SearchResult result = find_node(target_nodes_num[i], 2, 0, &firstline, 1, 2);
SearchResult result = find_node(current_target, 2, 0, &firstline, 1, 2);
if (result.count_in_father_line == -1) { if (result.count_in_father_line == -1) {
printf("0\n"); printf("0\n");
} }
else { else {
printf("1 "); printf("1 ");
for (int j = result.next_ans_pos - 1; j >= 0; j--) { for (int j = result.next_ans_pos - 1; j >= 0; j--) {
printf("%d ", ans[j]); printf("%lld ", ans[j]);
} }
printf("\n"); printf("\n");
} }