zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    NUC_TeamTEST_C && POJ2299(只有归并)
    BestCoder#15 A-LOVE(暴力)
    NUC_TeamTEST_B(贪心)
    2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
    CodeForces#275--DIV 2--A
    uva-1339Ancient Cipher
    uva748
    uva-465(overflow)
    uva10106(大数乘法)
    424
  • 原文地址:https://www.cnblogs.com/moonbay/p/2740780.html
Copyright © 2011-2022 走看看