码迷,mamicode.com
首页 > Windows程序 > 详细

POJ2585 Window Pains 题解 AOV

时间:2020-05-10 15:21:03      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:add   lan   space   name   head   ble   pac   scanf   org   

题目链接: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

标签:add   lan   space   name   head   ble   pac   scanf   org   

原文地址:https://www.cnblogs.com/quanjun/p/12863100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!