zoukankan      html  css  js  c++  java
  • Poj 2570 Fiber Network Floyd思想处理

    感觉非常有意思,也不难想。

    f[i][j] |= f[i][k] & f[k][j]

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <stack>
    
    using namespace std;
    
    typedef long long LL;
    const int maxn = 205;
    int n,val[maxn][maxn];
    bool e[maxn][maxn];
    char buf[1024];
    
    int getval(char *s) {
        int len = strlen(s),ret = 0;
        for(int i = 0;i < len;i++) {
            ret |= (1 << (s[i] - 'a'));
        }
        return ret;
    }
    
    void floyd() {
        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= n;j++) {
                for(int k = 1;k <= n;k++) {
                    val[j][k] |= val[j][i] & val[i][k];
                }
            }
        }
    }
    
    int main() {
        while(scanf("%d",&n),n) {
            memset(val,0,sizeof(val));
            int a,b;
            while(scanf("%d%d",&a,&b),a) {
                scanf("%s",buf);
                val[a][b] = getval(buf) ;
            }
            floyd();
            while(scanf("%d%d",&a,&b),a) {
                int cnt = 0;
                for(int i = 0;i < 26;i++) {
                    if(val[a][b] & (1 << i)) {
                        cnt++;
                        putchar(i + 'a');
                    }
                }
                if(cnt == 0) putchar('-');
                puts("");
            }
            puts("");
        }
        return 0;
    }
  • 相关阅读:
    Chrome开发者工具详解(1)
    Chrome开发者工具详解(2)
    Ubuntu ADSL拨号上网
    Bash中单引号和双引号的区别
    建立菜单
    波浪号和Hyphen扩展
    标准IO和重定向
    Bash变量扩展修改符
    mysql主键约束和唯一性约束
    Here文档
  • 原文地址:https://www.cnblogs.com/rolight/p/3857261.html
Copyright © 2011-2022 走看看