Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Wa到死一直查不到错,知道发现了。。

Posted by 3013216046 at 2014-08-01 22:00:52 on Problem 2446
当奇数格子个数不等于于偶数格子的时候一定是NO,然后就此直接A了。。。
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#define maxn 1000
#define inf 1000000
using namespace std;
int m, n, k, aa, bb;
int a[40][40];
bool g[maxn][maxn];
bool vis[maxn];
int link[maxn];
int dir[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
bool find(int x) {
    for (int i = 1; i < bb; i++) {
        if (g[x][i] && !vis[i]) {
            vis[i] = 1;
            if (!link[i] || find(link[i])) {
                link[i] = x;
                return true;
            }
        }
    }
    return false;
}
int main() {
    while (scanf("%d%d%d", &n, &m, &k) != EOF) {
        memset(link, 0, sizeof(link));
        memset(a, 0, sizeof(a));
        memset(g, 0, sizeof(g));
        for (int i = 0; i < k; i++) {
            int x, y;
            scanf("%d%d", &y, &x);
            a[x][y] = -1;
        }
        aa = 1, bb = 1;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++) {
                if (a[i][j] != -1) {
                    if ((i + j) & 1) a[i][j] = aa++;
                    else a[i][j] = bb++;
                }
            }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++) {
                if (((i + j) & 1) && a[i][j] != -1) {
                    for (int kk = 0; kk < 4; kk++) {
                        int rr = i + dir[kk][0], cc = j + dir[kk][1];
                        if (rr >= 1 && rr <= n && cc >= 1 && cc <= m && a[rr][cc] != -1)
                            g[a[i][j]][a[rr][cc]] = 1;
                    }
                }
            }
        if ((k & 1) || aa != bb) puts("NO");
        else {
            int ans = 0;
            for (int i = 1; i < aa; i++) {
                memset(vis, 0, sizeof(vis));
                if (find(i)) ans++;
            }
            if (ans == (m * n - k) / 2) puts("YES");
            else puts("NO");
        }
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator