CCF-CSP助教

用于存放第38,36,34,32次csp考试的答案

第36次 CSP 考试

移动

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
#include <iostream>
#include <algorithm>

using namespace std;

int n, k;

int cur_x, cur_y;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};

void move(int idx) {
int tar_x = cur_x + dx[idx];
int tar_y = cur_y + dy[idx];

if (tar_x < 1 || tar_x > n || tar_y < 1 || tar_y > n) {
return ;
}
cur_x = tar_x;
cur_y = tar_y;
}

int main() {
cin >> n >> k;
while(k --) {
int x, y;
string command;
cin >> x >> y >> command;

cur_x = x;
cur_y = y;
for (auto item : command) {
switch (item) {
case 'f': {
move(0);
break;
}
case 'b': {
move(1);
break;
}
case 'l': {
move(2);
break;
}
case 'r': {
move(3);
break;
}
}
}

cout << cur_x << " " << cur_y << endl;

}

return 0;
}

梦境巡查

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
#include <iostream>
#include <vector>
#include <algorithm>

using ll = long long;

const int N = 100005;

int n;
ll a[N], b[N];
ll c[N];
ll prefix_max[N];
ll suffix_max[N];

int main() {
scanf("%d", &n);
for (int i = 0; i <= n; i++) {
scanf("%lld", &a[i]);
}

b[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%lld", &b[i]);
}

c[0] = a[0];
for (int i = 1; i <= n; i++) {
c[i] = c[i - 1] + a[i] - b[i];
}

prefix_max[0] = c[0];
for (int i = 1; i <= n; i++) {
prefix_max[i] = std::max(prefix_max[i - 1], c[i]);
}

suffix_max[n] = c[n];
for (int i = n - 1; i >= 0; i--) {
suffix_max[i] = std::max(suffix_max[i + 1], c[i]);
}

for (int i = 1; i <= n; i++) {
ll p_max = prefix_max[i - 1];
ll s_max = suffix_max[i];
ll result = std::max(p_max, s_max + b[i]);
printf("%lld ", result);
}

return 0;
}


其他的题解:https://www.cnblogs.com/luckyblock/p/18596275

第38次 CSP 考试

正态分布

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <algorithm>

using namespace std;

int k;

int main() {
cin >> k;
while(k --) {
double u, f, n;
cin >> u >> f >> n;
double z = (n - u) / f;
z = z * 100;
long long ans = static_cast<long long>(z + 0.5);
cout << (ans / 10) + 1 << " " << (ans % 10) + 1<< endl;
}
return 0;
}

机器人复健指南

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
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int, int> PII;
typedef pair<PII, int> PIII;

const int N = 120;

queue<PIII> q;
bool st[N][N];
int n, k;
int x, y;
int ans;

int px[] = {1, 2, 2, 1, -1, -2, -2, -1}; // pointer x
int py[] = {2, 1, -1, -2, -2, -1, 1, 2};

int main() {
cin >> n >> k;
cin >> x >> y;
st[x][y] = true;
q.push({{x, y},k});
ans = 1;

while(q.size()) {
auto item = q.front();
q.pop();

int nx = item.first.first, ny = item.first.second; // nx = now x
int nk = item.second;
for (int i = 0; i < 8; i ++) {
int tx = nx + px[i]; // tx = target x
int ty = ny + py[i];
int tk = nk - 1;
if (tx < 1 || ty < 1 || tx > n || ty > n) {
continue;
}
if (st[tx][ty] == true) {
continue;
}

st[tx][ty] = true;
ans ++;
if (tk != 0) {
q.push({{tx, ty}, tk});
}
}


}
cout << ans << endl;


return 0;
}