【ABC421】D题求助
  • 板块学术版
  • 楼主TomRiddle
  • 当前回复3
  • 已保存回复3
  • 发布时间2025/8/30 22:38
  • 上次更新2025/8/31 16:37:23
查看原帖
【ABC421】D题求助
1054807
TomRiddle楼主2025/8/30 22:38

代码如下:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
    int sum = 0, f = 1;
    char ch = getchar();
    for (ch;ch < '0' || ch > '9';ch = getchar()) if (ch == '-') {f = -1;}
    for (ch;ch >= '0' && ch <= '9';ch = getchar()) sum = sum * 10 + ch - '0';
    return sum * f;
}
void write(int x)
{
    if (x < 0) x = -x, putchar('-');
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int gets()
{
    char ch = getchar();
    for (ch;ch != 'U' && ch != 'D' && ch != 'L' && ch != 'R';ch = getchar());
    return ch;
}
const int N = 1e5 + 5;
int rt, ct, ra, ca, n, m, l, ans;
pair<char, int> t[N], c[N];
void move(int &x, int &y, char mov, int step)
{
    if (mov == 'U') x -= step;
    else if (mov == 'D') x += step;
    else if (mov == 'L') y -= step;
    else y += step;
}
void add(char mov1, char mov2, int step)
{
    if (mov1 == mov2)
    {
        if (rt == ra && ct == ca) ans += step;
        return;
    }
    if (mov1 == 'U' && mov2 == 'D')
    {
        if (ct == ca && rt - step <= ra + step && rt >= ra && (rt - ra - 1) % 2 && rt - ra > 1) ans++;
    }
    else if (mov1 == 'D' && mov2 == 'U')
    {
        if (ct == ca && ra - step <= rt + step && ra >= rt && (ra - rt - 1) % 2 && ra - rt > 1) ans++;
    }
    else if (mov1 == 'L' && mov2 == 'R')
    {
        if (rt == ra && ct - step <= ca + step && ct >= ca && (ct - ca - 1) % 2 && ct - ca > 1) ans++;
    }
    else if (mov1 == 'R' && mov2 == 'L')
    {
        if (rt == ra && ca - step <= ct + step && ca >= ct && (ca - ct - 1) % 2 && ca - ct > 1) ans++;
    }
    else//方向不相同
    {
        int ch1, ch2;
        if (mov1 == 'U') ch1 = rt - ra;
        else if (mov1 == 'D') ch1 = ra - rt;
        else if (mov1 == 'L') ch1 = ct - ca;
        else ch1 = ca - ct;
        if (mov2 == 'U') ch2 = ra - rt;
        else if (mov2 == 'D') ch2 = rt - ra;
        else if (mov2 == 'L') ch2 = ca - ct;
        else ch2 = ct - ca;
        if (ch1 == ch2 && ch1 >= 0 && ch1 <= step) ans++;
    }
}
signed main()
{
	freopen("data.in", "r", stdin);
	freopen("std.out", "w", stdout);
	rt = read(), ct = read(), ra = read(), ca = read();
    n = read(), m = read(), l = read();
    int ch1 = 0, ch2 = 0;
    for (int i = 1;i <= m;i++) t[i] = {gets(), read()}, ch1 += t[i].second;
    for (int i = 1;i <= l;i++) c[i] = {gets(), read()}, ch2 += c[i].second;
    for (int i = 1, j = 1;i <= m && j <= l;)
    {
        int step = min(t[i].second, c[j].second);
        if (t[i].second == c[j].second)//如果步数相同
        {
            add(t[i].first, c[j].first, step);
            move(rt, ct, t[i].first, step);
            move(ra, ca, c[j].first, step);
            i++, j++;
        }
        else if (t[i].second > c[j].second)//如果t的步数更大,消耗完c
        {
            add(t[i].first, c[j].first, step);
            move(rt, ct, t[i].first, step);
            move(ra, ca, c[j].first, step);
            t[i].second -= step;
            j++;
        }
        else//反之
        {
            add(t[i].first, c[j].first, step);
            move(rt, ct, t[i].first, step);
            move(ra, ca, c[j].first, step);
            c[j].second -= step;
            i++;
        }
    }
    write(ans);
    return 0;
}

WA10,求dalao看看哪错了QAQ

如果觉得我的代码写的依托(确实),恳求给出hack,对拍了一万多组没拍出问题

2025/8/30 22:38
加载中...