zoukankan      html  css  js  c++  java
  • 题解 CF475B 【Strongly Connected City】

    这道题思路有三种:

    1.

    我们看到

    2 <= n, m <= 20
    

    数据范围不是很大,交点大约400,可以试着每个点dfs一次,然后找是否有一次都能到达其他点

    2.

    有些大佬会说:

    这不就是强联通分量水题吗?

    所以可以用Tarjan来求

    3.

    主要思路:瞎搞

    怎么瞎搞??

    我们可以仔细考虑一下,如果我们除了最外层的边以外,都可以通过最外层边到达各个边的话,那这个图是不是肯定是强联通的?

    那如果最外层都不是互联通的话,就肯定不符合题意。

    所以我们只需要判断一下最外层的街道是不是连通的就好了。

    没看懂自己感性理解下

    所以我只给出第三种解法的代码:(除输入外时间复杂度O(1))

    #include <algorithm>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define go(i, j, n, k) for (int i = j; i <= n; i += k)
    #define fo(i, j, n, k) for (int i = j; i >= n; i -= k)
    #define rep(i, x) for (int i = h[x]; i; i = e[i].nxt)
    #define mn 22
    #define inf 2147483647
    #define ll long long
    #define ld long double
    #define fi first
    #define se second
    #define root 1, n, 1
    #define lson l, m, rt << 1
    #define rson m + 1, r, rt << 1 | 1
    #define bson l, r, rt
    //#define LOCAL
    #define mod 
    #define Debug(...) fprintf(stderr, __VA_ARGS__)
    inline int read(){
        int f = 1, x = 0;char ch = getchar();
        while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
        while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
        return x * f;
    }
    //This is AC head above...
    int n, m, heng[mn], shu[mn];
    char h[mn << 2], s[mn << 2];
    int main(){
        n = read(), m = read();
        scanf("%s", h + 1);
        go(i, 1, n, 1){
            heng[i] = h[i] == '<' ? 0 : 1; // 0 -> zuo 1 -> you
        }
        scanf("%s", s + 1);
        go(i, 1, m, 1) {
            shu[i] = s[i] == '^' ? 0 : 1; // 0 -> shang 1 -> xia
        }
        if((heng[1] == 1 && heng[n] == 0 && shu[1] == 0 && shu[m] == 1) || (heng[1] == 0 && heng[n] == 1 && shu[1] == 1 && shu[m] == 0)) 
        {
            puts("YES");
        }
        else
        {
            puts("NO");
        }
    #ifdef LOCAL
        Debug("
    My Time: %.3lfms
    ", (double)clock() / CLOCKS_PER_SEC);
    #endif
        return 0;
    }
    
  • 相关阅读:
    Uva 10779 collector's problem
    poj 2728 最优比率树(最小生成树问题)
    LA 3126 二分图匹配 最小路径覆盖
    poj 1149 最大流构图
    Step By Step(Java XML篇)
    Step By Step(Java 输入输出篇)
    Step By Step(Java 集合篇)
    Step By Step(Java 线程篇)
    Step By Step(Java 反射篇)
    Step By Step(Java 国际化篇)
  • 原文地址:https://www.cnblogs.com/yizimi/p/10056290.html
Copyright © 2011-2022 走看看