POJ2585 Window Pains 题解 AOV

Posted quanjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ2585 Window Pains 题解 AOV相关的知识,希望对你有一定的参考价值。

题目链接:http://poj.org/problem?id=2585

示例代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int maxn = 11, maxm = 1100;
struct Edge {
    int v, nxt;
    Edge() {};
    Edge(int _v, int _nxt) { v = _v; nxt = _nxt; }
} edge[maxm];
int ecnt, head[maxn];
void init() {
    ecnt = 0;
    memset(head, -1, sizeof(head));
}
void addedge(int u, int v) {
    edge[ecnt] = Edge(v, head[u]);
    head[u] = ecnt ++;
}
char s[11];
int a[5][5], in[maxn];
queue<int> que;
bool handle() {
    while (!que.empty()) que.pop();
    for (int i = 1; i <= 9; i ++) if (!in[i]) que.push(i);
    for (int t = 1; t <= 9; t ++) {
        if (que.empty()) return false;
        int u = que.front();
        que.pop();
        for (int i = head[u]; i != -1; i = edge[i].nxt) {
            int v = edge[i].v;
            in[v] --;
            if (in[v] == 0) que.push(v);
        }
    }
    return true;
}

int main() {
    while (~scanf("%s", s) && s[0] != ‘E‘) {
        for (int i = 1; i <= 4; i ++)
            for (int j = 1; j <= 4; j ++)
                scanf("%d", &a[i][j]);
        init();
        memset(in, 0, sizeof(in));
        for (int i = 1; i <= 9; i ++) {
            int x = (i-1)/3+1;
            int y = (i-1)%3+1;
            for (int j = 0; j < 2; j ++) for (int k = 0; k < 2; k ++) {
                int num = a[x+j][y+k];
                if (num != i) {
                    addedge(i, num);
                    in[num] ++;
                }
            }
        }
        puts(handle() ? "THESE WINDOWS ARE CLEAN" : "THESE WINDOWS ARE BROKEN");
        scanf("%s", s);
    }
    return 0;
}

以上是关于POJ2585 Window Pains 题解 AOV的主要内容,如果未能解决你的问题,请参考以下文章

POJ 2585 Window Pains 题解

POJ 2585 Window Pains 拓扑排序

POJ 2585Window Pains

poj 2585 Window Pains 解题报告

poj 2585 Window Pains 暴力枚举排列

POJ 2823 Sliding Window 题解