hdu 2181暴搜

暴搜就可以过了,简单。

/*

 * hdu2181/win.cpp

 * Created on: 2012-10-25

 * Author    : ben

 */

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <ctime>

#include <iostream>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

#include <stack>

#include <string>

#include <vector>

#include <deque>

#include <list>

#include <functional>

#include <numeric>

#include <cctype>

using namespace std;

typedef struct MyPoint {

    int a[3];

}MyPoint;

MyPoint points[20];

void init() {

    for(int i = 0; i < 20; i++) {

        for(int j = 0; j < 3; j++) {

            scanf("%d", &points[i].a[j]);

        }

        sort(points[i].a, points[i].a + 3);

    }

}

int ans[20], num;

bool isvisited[21];

void dfs(int now) {

    if(now == 20) {

        int i;

        for(i = 0; i < 3; i++) {

            if(points[ans[now - 1] - 1].a[i] == ans[0]) {

                break;

            }

        }

        if(i < 3) {

            num++;

            printf("%d: ", num);

            for(int i = 0; i <= 20; i++) {

                printf(" %d", ans[i % 20]);

            }

            putchar('\n');

        }

        return ;

    }

    for(int i = 0; i < 3; i++) {

        int t = points[ans[now - 1] - 1].a[i];

        if(!isvisited[t]) {

            ans[now] = t;

            isvisited[t] = true;

            dfs(now + 1);

            isvisited[t] = false;

        }

    }

}

int main() {

#ifndef ONLINE_JUDGE

    freopen("data.in", "r", stdin);

#endif

    init();

    int m;

    while(scanf("%d", &m) == 1 && m > 0) {

        fill(isvisited, isvisited + 20, false);

        ans[0] = m;

        num = 0;

        isvisited[m] = true;

        dfs(1);

    }

    return 0;

}

你可能感兴趣的:(HDU)