洛谷ACpojWA求调
查看原帖
洛谷ACpojWA求调
928418
MLE_Automaton算法萌新楼主2025/1/1 12:58
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<=(b);i++)
#define pre(i, a, b) for(int i=(a);i>=(b);i--)
#define INF 0x3f3f3f3f
#define llINF 0x3f3f3f3f3f3f3f3f
#define bigpq(type) priority_queue<type>
#define smpq(type) priority_queue<type,vector<type>,greater<type>>
#define mem(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
/**********************************************************************
    lgP10493.cpp created by Dennis2013 on 31-12-2024 周二 at 20:48:15
**********************************************************************/
int x, y; char d[3];
int li(int x, int y)
{
    static const int tab[3][3] = {
            {0, 3, 4},
            {3, 6, 6},
            {4, 6, 7},
    };
    x = abs(x), y = abs(y);
    if (x < 3 && y < 3) return tab[x][y];
    if (x < 3) return y / 3 * 2 + tab[0][y % 3] + x;
    if (y < 3) return x / 3 * 2 + tab[x % 3][0] + y;
    return x / 3 * 2 + y / 3 * 2 + x % 3 + y % 3;
}
int tang(int x, int y) //平行x
{
    static const int tab[3][3] = {
            {4, 5, 5},
            {1, 2, 3},
            {4, 5, 5},
    };
    if (x < 0) x = -x - 1;
    if (y < 0) y = -y;
    if (x < 3 && y < 3) return tab[x][y];
    int res = 0x7fffffff;
    rep(i, 0, 2) res = min(res, min(li(x - 1, y - i), li(x + 2, y - i)) + i + 1);
    return res;
}
int main()
{
    while (~scanf("%s%d%d", d, &x, &y))
    {
        if (d[0] == 'U') printf("%d\n", li(x, y));
        if (d[0] == 'V') printf("%d\n", tang(x, y));
        if (d[0] == 'H') printf("%d\n", tang(y, -x));
    }
    return 0;
}

哪里错了啊qwq

2025/1/1 12:58
加载中...