This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int* gen_shuffled_array(int n) | ||
{ | ||
int cur = 0; | ||
int offset = 1; | ||
int flip = 0; | ||
int next_start = 0; | ||
int* result = (int*)malloc(n * sizeof(int)); | ||
int result_index = 0; | ||
|
||
while (next_start < n) { | ||
if (flip) { | ||
cur = next_start + offset; | ||
// next_start = next_start; | ||
} else { | ||
cur = next_start; | ||
next_start += offset; | ||
} | ||
|
||
while (cur < n) { | ||
result[result_index++] = cur; | ||
cur += offset * 2; | ||
} | ||
|
||
if (cur - offset < n) { | ||
flip = 0; | ||
} else { | ||
flip = 1; | ||
} | ||
offset *= 2; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void test_main() | ||
{ | ||
int* index = gen_shuffled_array(7); | ||
int k[7] = { 1, 2, 3, 4, 6, 5, 7 }; | ||
int result[7]; | ||
|
||
for (int i = 0; i < 7; i++) { | ||
result[index[i]] = k[i]; | ||
} | ||
|
||
for (int i = 0; i < 7; i++) { | ||
printf("%d ", result[i]); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
scanf("%d", &n); | ||
int* input = (int*)malloc(n * sizeof(int)); | ||
for (int i = 0; i < n; i++) { | ||
scanf("%d", &input[i]); | ||
} | ||
int* index = gen_shuffled_array(n); | ||
int* result = (int*)malloc(n * sizeof(int)); | ||
for (int i = 0; i < n; i++) { | ||
result[index[i]] = input[i]; | ||
} | ||
for (int i = 0; i < n; i++) { | ||
printf("%d ", result[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include<stdio.h> | ||
int main() { | ||
int a, b; | ||
scanf("%d %d", &a, &b); | ||
printf("%d", a+b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <stdio.h> | ||
|
||
#define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
#define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
|
||
int main() | ||
{ | ||
int n, x; | ||
scanf("%d %d", &n, &x); | ||
|
||
int count = 0; | ||
int k = 1; | ||
|
||
do { | ||
if (x == 0) { | ||
count += (n / (k * 10) - 1) * k; | ||
count += MIN(n % (k * 10) + 1, k); | ||
} else { | ||
count += (n / (k * 10)) * k; | ||
count += MIN(MAX(n % (k * 10) - k * x + 1, 0), k); | ||
} | ||
k *= 10; | ||
} while (k < n); | ||
|
||
printf("%d", count); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# H1 | ||
|
||
## H1-1 | ||
|
||
给定一组数,总是重复如下操作: | ||
|
||
- 取第一个数放到另一边 | ||
- 将第一个数放到队列的末尾 | ||
|
||
直到队列为空,给出最后另一边的结果,反推出原来的队列。 | ||
|
||
## H1-2 | ||
|
||
A+B 没什么好说的 | ||
|
||
## H1-3 | ||
|
||
计算 $[1,N]$ 中数字 $x$ 出现的次数(十进制表示) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
# H2 | ||
|
||
## H2-1 队列 | ||
|
||
### 描述 | ||
|
||
请你实现一个队列(queue),支持如下操作: | ||
|
||
- `push(x)`:向队列中加入一个数 x。 | ||
- `pop()`:将队首弹出。如果此时队列为空,则不进行弹出操作,并输出 `ERR_CANNOT_POP`。 | ||
- `query()`:输出队首元素。如果此时队列为空,则输出 `ERR_CANNOT_QUERY`。 | ||
- `size()`:输出此时队列内元素个数。 | ||
|
||
### 输入 | ||
|
||
第一行,一个整数 `n`,表示操作的次数。 | ||
|
||
接下来 `n` 行,每行表示一个操作。格式如下: | ||
|
||
- 1 x,表示将元素 x 加入队列。 | ||
- 2,表示将队首弹出队列。 | ||
- 3,表示查询队首。 | ||
- 4,表示查询队列内元素个数。 | ||
|
||
对于 100% 的测试数据,满足 $n\leq 10000n\leq 10000$,且被插入队列的所有元素的值为$[1,1000000]$以内的正整数。 | ||
|
||
### 输出 | ||
|
||
输出若干行,对于每个操作,按「题目描述」输出结果。 | ||
|
||
每条输出之间应当用空行隔开。 | ||
|
||
**输入样例 1** | ||
|
||
```txt | ||
13 | ||
1 2 | ||
3 | ||
4 | ||
1 233 | ||
3 | ||
2 | ||
3 | ||
2 | ||
4 | ||
3 | ||
2 | ||
1 144 | ||
3 | ||
``` | ||
|
||
**输出样例 1** | ||
|
||
```txt | ||
2 | ||
1 | ||
2 | ||
233 | ||
0 | ||
ERR_CANNOT_QUERY | ||
ERR_CANNOT_POP | ||
144 | ||
``` | ||
|
||
## H2-2 栈 | ||
|
||
### 描述 | ||
|
||
请你实现一个栈(stack),支持如下操作: | ||
|
||
- `push(x)`:向栈中加入一个数 x。 | ||
- `pop()`:将栈顶弹出。如果此时栈为空则不进行弹出操作,输出 `Empty`。 | ||
- `query()`:输出栈顶元素,如果此时栈为空则输出 `Anguei!`。 | ||
- `size()`:输出此时栈内元素个数。 | ||
|
||
### 输入 | ||
|
||
每组数据第一行是一个整数,表示操作的次数 n。 | ||
|
||
接下来 n 行,每行表示一个操作,格式如下: | ||
|
||
- 1 x,表示将元素 x 加入栈。 | ||
- 2,表示将栈顶弹出栈。 | ||
- 3,表示查询栈顶。 | ||
- 4,表示查询栈内元素个数。 | ||
|
||
对于 100% 的测试数据,满足 $n\leq10000$,且被插入队列的所有元素的值为$[1,1000000]$以内的正整数。 | ||
|
||
#### 输出 | ||
|
||
对于每组数据,按照「题目描述」中的要求依次输出。每次输出占一行。 | ||
|
||
**输入样例 1** | ||
|
||
```txt | ||
5 | ||
1 2 | ||
3 | ||
4 | ||
2 | ||
3 | ||
``` | ||
|
||
**输出样例 1** | ||
|
||
```txt | ||
2 | ||
1 | ||
Anguei! | ||
``` | ||
|
||
**输入样例 2** | ||
|
||
```txt | ||
3 | ||
2 | ||
3 | ||
4 | ||
``` | ||
|
||
**输出样例 2** | ||
|
||
``` | ||
Empty | ||
Anguei! | ||
0 | ||
``` | ||
|
||
## H2-3 堆 | ||
|
||
### 描述 | ||
|
||
给定一个数列,初始为空,请支持下面三种操作: | ||
|
||
- 1 x:给定一个整数 x,请将 x 加入到数列中。 | ||
- 2:输出数列中最小的数。 | ||
- 3:删除数列中最小的数(如果有多个数最小,只删除 1 个)。 | ||
- 4:输出数列的大小 | ||
|
||
### 输入 | ||
|
||
第一行是一个整数,表示操作的次数 n。 | ||
接下来 n 行,每行表示一次操作。每行首先有一个整数 op 表示操作类型。 | ||
|
||
- 1 x:表示要将 x 加入数列。 | ||
- 2,表示要求输出数列中的最小数。若堆为空,则输出 `ERR_CANNOT_QUERY`。 | ||
- 3,表示删除数列中的最小数。如果有多个数最小,只删除 1 个。若堆为空,则输出 `ERR_CANNOT_POP`。 | ||
- 4,表示要输出数列的大小。 | ||
|
||
对于 100% 的测试数据,满足 $n\leq 10000n\leq 10000$,且被插入队列的所有元素的值为$[1,1000000]$以内的正整数。 | ||
|
||
### 输出 | ||
|
||
输出若干行,对于每个操作,按「题目描述」输出结果。 | ||
|
||
每条输出之间应当用空行隔开。 | ||
|
||
**输入样例 1** | ||
|
||
```txt | ||
5 | ||
1 2 | ||
1 5 | ||
2 | ||
3 | ||
2 | ||
``` | ||
|
||
**输出样例 1** | ||
|
||
```txt | ||
2 | ||
5 | ||
``` | ||
|
||
**输入样例 2** | ||
|
||
```txt | ||
8 | ||
2 | ||
2 | ||
4 | ||
3 | ||
1 28079 | ||
2 | ||
1 23826 | ||
2 | ||
``` | ||
|
||
**输出样例 2** | ||
|
||
```txt | ||
ERR_CANNOT_QUERY | ||
ERR_CANNOT_QUERY | ||
0 | ||
ERR_CANNOT_POP | ||
28079 | ||
23826 | ||
``` |
File renamed without changes.