hdu1181暴搜

数据量很少,暴搜就可以过了

/*

 * hdu1181/win.cpp

 * Created on: 2012-7-30

 * 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;

const int MAXN = 26;

bool mymap[MAXN][MAXN], visited[MAXN];



bool dfs(int s, int e) {

    if(mymap[s][e]) {

        return true;

    }

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

        if(i != s && mymap[s][i] && !visited[i]) {

            visited[i] = true;

            if(dfs(i, e)) {

                return true;

            }

        }

    }

    return false;

}



int main() {

#ifndef ONLINE_JUDGE

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

#endif

    char str[200];

    int a, b;

    memset(mymap, false, sizeof(mymap));

    while(scanf("%s", str) != EOF) {

        if(strcmp(str, "0") == 0) {

            memset(visited, false, sizeof(visited));

            visited[1] = true;

            if(dfs(1, 12)) {

                puts("Yes.");

            }else {

                puts("No.");

            }

            memset(mymap, false, sizeof(mymap));

        }else {

            a = str[0] - 'a';

            b = strlen(str);

            b = str[b - 1] - 'a';

            mymap[a][b] = true;

        }

    }

    return 0;

}

你可能感兴趣的:(HDU)