水题笔记_ ARC093[模拟, 构造]

日常只会CD, 什么时候才能像他们一样做EF呢…

C

记录每个节点走与不走的费用差, 然后输出的时候用总的费用减去费用差即可

沙茶的 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define MAXN (100000 + 5)
#define LL long long
#define abs(a) (((a) > 0) ? (a) : (-(a)))
using namespace std;
LL a[MAXN], b[MAXN], sum, n;
int main()
{
scanf("%lld", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), sum += abs(a[i] - a[i - 1]);
sum += abs(a[n]);
for (int i = 1; i <= n; i++)
b[i] = abs(abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i - 1]));
for (int i = 1; i <= n; i++)
printf("%lld\n", sum - b[i]);
return 0;
}

D

一开始没有注意$A, B$与最大矩阵大小之间的差距这么大, 乱搞了半天没什么效果

后来发现直接把矩阵分成两半, 一半#, 一半., 然后往#一半填$A$个., 往.一半填$B$个#即可

沙茶的 代码

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
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define MAXN (100)
#define LL long long
#define abs(a) (((a) > 0) ? (a) : (-(a)))
using namespace std;
const char print[] = {'.', '#'};
int n;
bool a[MAXN + 5][MAXN + 5], change = false;
int main()
{
int ta, tb;
scanf("%d%d", &ta, &tb);
if (!ta || !tb)
{
printf(ta ? "." : "#");
return 0;
}
for (int i = 1; i <= MAXN; i++)
for (int j = 1; j <= MAXN; j++)
{
if (i <= (MAXN / 2)) a[i][j] = false;
else a[i][j] = true;
}
int cnta = 1, cntb = 1;
for (int i = 1; i <= MAXN; i += 2)
{
for (int j = 1; j <= MAXN; j += 2)
{
if (cntb >= tb)
break;
a[i][j] = true;
++cntb;
}
if (cntb >= tb)
break;
}
for (int i = MAXN; i >= 1; i -= 2)
{
for (int j = MAXN; j >= 1; j -= 2)
{
if (cnta >= ta)
break;
a[i][j] = false;
++cnta;
}
if (cnta >= ta)
break;
}
printf("%d %d\n", MAXN, MAXN);
for (int i = 1; i <= MAXN; i++)
{
for (int j = 1; j <= MAXN; j++)
printf("%c", print[a[i][j] ^ change]);
puts("");
}
return 0;
}

/*
#.#.#.
.#.#.#
#.#.#.
......
......
#.#.#.
*/

By Cansult(9kyu)