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

C

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

沙茶的 代码

#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$个#即可

沙茶的 代码

#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)