Compare commits
13 Commits
try-fast-r
...
04_02
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d4ad11b89
|
||
|
|
b7b8af4811
|
||
|
|
cf1e94a5d1
|
||
|
|
744a773e95
|
||
|
|
1d3a916eb5
|
||
|
|
3aabda4b43
|
||
|
|
2642acd00a
|
||
|
|
32bd7e91fd
|
||
|
|
a370d5a723
|
||
|
|
a91c9637e8
|
||
|
|
4726deb30c
|
||
|
|
03e0e30a95
|
||
|
|
8a44704bdd
|
@@ -77,7 +77,7 @@ BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
QualifierAlignment: Leave
|
||||
CompactNamespaces: false
|
||||
|
||||
137
2023202/main.cpp
137
2023202/main.cpp
@@ -1,138 +1,47 @@
|
||||
#include <stdio.h>
|
||||
|
||||
template <class E> class Node {
|
||||
private:
|
||||
E content;
|
||||
Node<E> *next;
|
||||
|
||||
public:
|
||||
Node(const E &_content) : content(_content), next(this){};
|
||||
Node(const E &_content, Node<E> *nextPtr)
|
||||
: content(_content), next(nextPtr){};
|
||||
void setNext(Node<E> *_ptr) {
|
||||
this->next = _ptr;
|
||||
}
|
||||
E &getContent() {
|
||||
return this->content;
|
||||
}
|
||||
Node<E> *getNextPtr() {
|
||||
return this->next;
|
||||
}
|
||||
struct Node{
|
||||
int prev, next;
|
||||
};
|
||||
|
||||
template <class E> class Iterator {
|
||||
private:
|
||||
Node<E> *current;
|
||||
|
||||
public:
|
||||
Iterator(Node<E> *start) : current(start){};
|
||||
E &peekNext() {
|
||||
return this->current->getNextPtr()->getContent();
|
||||
}
|
||||
void next() {
|
||||
this->current = this->current->getNextPtr();
|
||||
}
|
||||
E &peek() {
|
||||
return this->current->getContent();
|
||||
}
|
||||
Node<E> *peekNode() {
|
||||
return this->current;
|
||||
}
|
||||
void insertHere(const E &newItem) {
|
||||
this->current->setNext(
|
||||
new Node<E>(newItem, this->current->getNextPtr()));
|
||||
}
|
||||
};
|
||||
|
||||
template <class E> class List {
|
||||
private:
|
||||
// int _length;
|
||||
Node<E> head;
|
||||
|
||||
public:
|
||||
List(const E &dummyValue)
|
||||
: head(Node<E>(dummyValue)){
|
||||
// this->_length = 0;
|
||||
};
|
||||
void insert(const E &target, const E &newItem) {
|
||||
Iterator<E> iter = Iterator<E>(&this->head);
|
||||
// Remember to add a loop to stop at length!!;
|
||||
while (iter.peek() != target) {
|
||||
iter.next();
|
||||
}
|
||||
iter.insertHere(newItem);
|
||||
// this->_length++;
|
||||
}
|
||||
void remove(const E &target) {
|
||||
Iterator<E> iter = Iterator<E>(&this->head);
|
||||
while (iter.peekNext() != target) {
|
||||
iter.next();
|
||||
}
|
||||
Node<E> *toBeDeleted = iter.peekNode()->getNextPtr();
|
||||
iter.peekNode()->setNext(toBeDeleted->getNextPtr());
|
||||
delete toBeDeleted;
|
||||
// this->_length--;
|
||||
}
|
||||
Iterator<E> iterate() {
|
||||
return Iterator<E>(&this->head);
|
||||
}
|
||||
};
|
||||
|
||||
int read_num() {
|
||||
int summ = 0;
|
||||
char c = getchar();
|
||||
while (c < '0' || c > '9') {
|
||||
c = getchar();
|
||||
}
|
||||
while (c >= '0' && c <= '9') {
|
||||
summ = summ * 10 + c - '0';
|
||||
c = getchar();
|
||||
}
|
||||
return summ;
|
||||
}
|
||||
Node map[100000];
|
||||
|
||||
int main() {
|
||||
List<int> aList(0);
|
||||
aList.insert(0, 1);
|
||||
map[0].prev = 1;
|
||||
map[0].next = 1;
|
||||
map[1].prev = 0;
|
||||
map[1].next = 0;
|
||||
int n;
|
||||
int cmd, x, y;
|
||||
// scanf("%d", &n);
|
||||
n = read_num();
|
||||
scanf("%d", &n);
|
||||
while (n) {
|
||||
cmd = read_num();
|
||||
x = read_num();
|
||||
// scanf("%d %d", &cmd, &x);
|
||||
switch (cmd) {
|
||||
scanf("%d %d", &cmd, &x);
|
||||
switch(cmd) {
|
||||
case 1: {
|
||||
// scanf("%d", &y);
|
||||
y = read_num();
|
||||
aList.insert(x, y);
|
||||
scanf("%d", &y);
|
||||
map[y].prev = x;
|
||||
map[y].next = map[x].next;
|
||||
map[x].next = y;
|
||||
map[map[y].next].prev = y;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
Iterator<int> iter = aList.iterate();
|
||||
while (iter.peek() != x) {
|
||||
iter.next();
|
||||
}
|
||||
printf("%d\n", iter.peekNext());
|
||||
printf("%d\n", map[x].next);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
aList.remove(x);
|
||||
map[map[x].prev].next = map[x].next;
|
||||
map[map[x].next].prev = map[x].prev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
n--;
|
||||
}
|
||||
|
||||
Iterator<int> iter = aList.iterate();
|
||||
iter.next();
|
||||
while (true) {
|
||||
int content = iter.peek();
|
||||
if (content == 0) {
|
||||
break;
|
||||
}
|
||||
printf("%d\n", content);
|
||||
iter.next();
|
||||
int cur = map[0].next;
|
||||
while (cur != 0) {
|
||||
printf("%d\n", cur);
|
||||
cur = map[cur].next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
48
2023203/main.cpp
Normal file
48
2023203/main.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
// 创建一个栈,拿到一个数,与栈顶比较,如果比栈顶小,压栈(正在波峰向波谷下降)
|
||||
// 比栈顶大,弹栈并计数;和栈顶相同,计数并且压入。
|
||||
|
||||
struct NumberNode {
|
||||
int data;
|
||||
int count;
|
||||
};
|
||||
|
||||
|
||||
long long totalPairs;
|
||||
NumberNode powers[500010];
|
||||
|
||||
int main() {
|
||||
int len = 1;
|
||||
int N;
|
||||
int input;
|
||||
totalPairs = 0;
|
||||
powers[0].data = 0;
|
||||
powers[0].count = 0;
|
||||
scanf("%d", &N);
|
||||
scanf("%d", &powers[1].data);
|
||||
powers[1].count = 1;
|
||||
N--;
|
||||
for (int i = 0; i < N; i++) {
|
||||
scanf("%d", &input);
|
||||
while (len != 0 && powers[len].data < input) {
|
||||
totalPairs += powers[len].count;
|
||||
len--;
|
||||
}
|
||||
if (len == 0 ) {
|
||||
powers[1].data = input;
|
||||
powers[1].count = 1;
|
||||
len = 1;
|
||||
} else {
|
||||
if (powers[len].data == input) {
|
||||
totalPairs += powers[len].count + (len > 1);
|
||||
powers[len].count++;
|
||||
}
|
||||
else {
|
||||
totalPairs += 1;
|
||||
powers[++len] = NumberNode {input, 1};
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%lld", totalPairs);
|
||||
return 0;
|
||||
}
|
||||
101
2023204/main.cpp
Normal file
101
2023204/main.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#define DEAD false
|
||||
#define ALIVE true
|
||||
// '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.
|
||||
|
||||
int ans[200] = {0};
|
||||
long long dead_nodes_num[105] = {0};
|
||||
int total_dead_nodes = 0;
|
||||
long long target_nodes_num[105] = {0};
|
||||
int total_target_nodes = 0;
|
||||
long long max_spawned_num = 0;
|
||||
|
||||
struct Layer {
|
||||
long long start_num;
|
||||
long long end_num;
|
||||
std::vector<long long> dead_nodes;
|
||||
};
|
||||
|
||||
Layer tree[150] = {0};
|
||||
|
||||
void create_tree(long long start_num, long long prev_alive, int layer, int next_dead_node_ptr) {
|
||||
tree[layer].start_num = start_num;
|
||||
prev_alive *= 2;
|
||||
tree[layer].end_num = start_num + prev_alive - 1;
|
||||
while (next_dead_node_ptr < total_dead_nodes &&
|
||||
dead_nodes_num[next_dead_node_ptr] <= tree[layer].end_num) {
|
||||
tree[layer].dead_nodes.push_back(dead_nodes_num[next_dead_node_ptr++]);
|
||||
prev_alive--;
|
||||
}
|
||||
if (prev_alive == 0 || tree[layer].end_num >= target_nodes_num[total_target_nodes - 1]) {
|
||||
max_spawned_num = tree[layer].end_num;
|
||||
return;
|
||||
}
|
||||
|
||||
create_tree(tree[layer].end_num + 1, prev_alive, layer + 1, next_dead_node_ptr);
|
||||
}
|
||||
|
||||
void find_ans(long long target, int layer) {
|
||||
ans[layer] = target;
|
||||
if (layer == 1) {
|
||||
return;
|
||||
}
|
||||
long long count_in_layer = (target - tree[layer].start_num) / 2;
|
||||
for (int i = 0; i < tree[layer - 1].dead_nodes.size(); i++) {
|
||||
if (count_in_layer < tree[layer - 1].dead_nodes[i] - tree[layer - 1].start_num - i) {
|
||||
find_ans(tree[layer - 1].start_num + i + count_in_layer, layer - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// til the end_num
|
||||
find_ans(tree[layer - 1].start_num + tree[layer - 1].dead_nodes.size() + count_in_layer,
|
||||
layer - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
scanf("%d %d", &total_dead_nodes, &total_target_nodes);
|
||||
for (int i = 0; i < total_dead_nodes; i++) {
|
||||
scanf("%lld", &dead_nodes_num[i]);
|
||||
}
|
||||
for (int i = 0; i < total_target_nodes; i++) {
|
||||
scanf("%lld", &target_nodes_num[i]);
|
||||
}
|
||||
|
||||
tree[1].start_num = 1;
|
||||
tree[1].end_num = 1;
|
||||
if (dead_nodes_num[0] == 1) {
|
||||
for (int i = 0; i < total_target_nodes; i++) {
|
||||
if (target_nodes_num[i] == 1) {
|
||||
printf("1\n"); //
|
||||
}
|
||||
else {
|
||||
printf("0\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
create_tree(2, 1, 2, 0);
|
||||
|
||||
// printf("Max spawn: %lld\n", max_spawned_num);
|
||||
|
||||
for (int i = 0; i < total_target_nodes; i++) {
|
||||
if (target_nodes_num[i] > max_spawned_num) {
|
||||
printf("0\n");
|
||||
continue;
|
||||
}
|
||||
int layer_pos = 1;
|
||||
while (tree[layer_pos].end_num < target_nodes_num[i]) {
|
||||
layer_pos++;
|
||||
}
|
||||
find_ans(target_nodes_num[i], layer_pos);
|
||||
for (int j = 1; j <= layer_pos; j++) {
|
||||
printf("%lld ", ans[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user