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;
    }
    
  • 相关阅读:
    VysorPro助手
    Play 2D games on Pixel running Android Nougat (N7.1.2) with Daydream View VR headset
    Play 2D games on Nexus 6P running Android N7.1.1 with Daydream View VR headset
    Native SBS for Android
    ADB和Fastboot最新版的谷歌官方下载链接
    How do I install Daydream on my phone?
    Daydream Controller手柄数据的解析
    蓝牙BLE传输性能及延迟分析
    VR(虚拟现实)开发资源汇总
    Android(Java)控制GPIO的方法及耗时分析
  • 原文地址:https://www.cnblogs.com/yizimi/p/10056290.html
Copyright © 2011-2022 走看看