• 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;
    }
  • 相关阅读:
    CSS选择器之伪类选择器(元素)
    CSS选择器之基本选择器+属性选择器
    bugku 点击1000000次
    bugku web 5
    bugku 矛盾 30
    bugku 域名解析题 50
    bugku 好多压缩包
    六子冲 模拟棋盘
    poj3126 Prime Path(c语言)
    poj1426 Find The Multiple(c语言巧解)
  • 原文地址:https://www.cnblogs.com/moonbay/p/2740780.html
Copyright © 2020-2023  润新知