OTL???

P3355 骑士共存问题

Rossie65536 @ 2020-08-01 12:32:35

OTL是啥?这代码有毒?哪位聚聚过来看看QwQ

#include <bits/stdc++.h>

using namespace std;

const int N = 301;

int n, k, Map[N][N];
struct Edge {
    int nxt, to;
} edge[(N * N) << 3];
int head[N * N], tot;
int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2}, dy[8] = {2, -2, 2, -2, 1, -1, 1, -1};
bool vis[N * N];
int f[N * N];

inline void add(int x, int y) {
    edge[++tot].nxt = head[x], head[x] = tot, edge[tot].to = y;
}

inline int GetNum(int x, int y) { return (x - 1) * n + y; }

inline bool find(int x) {
    for (int i = head[x]; i; i = edge[i].nxt) {
        int y = edge[i].to;
        if (vis[y]) continue;
        vis[y] = 1;
        if (!f[y] || find(f[y])) {
            f[y] = x;
            return 1;
        }
    }
    return 0;
}

inline int solve() {
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (!Map[i][j] && (i + j) % 2) {
                memset(vis, 0, sizeof(vis));
                if (find(GetNum(i, j))) ans++;
            }
    cout << n * n - k - ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    for (int i = 1; i <= k; ++i) {
        int x, y;
        cin >> x >> y;
        Map[x][y] = 1;
    }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (!Map[i][j] && (i + j) % 2)
                for (int z = 0; z < 8; ++z) {
                    int tx = dx[z] + i, ty = dy[z] + j;
                    if (tx < 1 || tx > n || ty < 1 || ty > n || Map[tx][ty])
                        continue;
                    add(GetNum(i, j), GetNum(tx, ty));
                    add(GetNum(tx, ty), GetNum(i, j));
                }

    solve();

    return 0;
}

by ezoixx130 @ 2020-08-01 12:34:30

@Roisse 你 solve 函数定义了返回类型没有返回值。


by WanderingTrader @ 2020-08-01 12:37:27

@Roisse 那个是OLE,你输出太多了


by Smile_Cindy @ 2020-08-01 12:49:15

OLE

这个是OLE


by so_weak @ 2020-08-01 13:04:20

改成

inline void solve() {
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (!Map[i][j] && (i + j) % 2) {
                memset(vis, 0, sizeof(vis));
                if (find(GetNum(i, j))) ans++;
            }
    cout << n * n - k - ans;
}

|