zoukankan      html  css  js  c++  java
  • POJ 3660 Cow Contest(flod)

    题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的。

    分析:

    1、a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所有牛的大小关系都存入a。

    2、对于每一头牛,cntfront表示比它强的牛的个数,cntrear表示比它弱的牛的个数,若两者相加等于N-1,那该牛的名次自然可以确定。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 100 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int a[MAXN][MAXN];
    int ans;
    int N, M;
    int solve(){
        for(int i = 1; i <= N; ++i){
            int cntfront = 0, cntrear = 0;
            for(int j = 1; j <= N; ++j){
                if(a[j][i]) ++cntfront;
                if(a[i][j]) ++cntrear;
            }
            if(cntfront + cntrear == N - 1) ++ans;
        }
        return ans;
    }
    int main(){
        scanf("%d%d", &N, &M);
        for(int i = 0; i < M; ++i){
            int u, v;
            scanf("%d%d", &u, &v);
            a[u][v] = 1;
        }
        for(int k = 1; k <= N; ++k){
            for(int i = 1; i <= N; ++i){
                for(int j = 1; j <= N; ++j){
                    if(a[i][k] && a[k][j]) a[i][j] = 1;
                }
            }
        }
        printf("%d\n", solve());
        return 0;
    }
    

      

  • 相关阅读:
    20150922号HTML答案+css
    20150921css2
    20150917-html第二次课
    20150916-html第一次课
    Codeforces Round #527 (Div. 3) . F Tree with Maximum Cost
    Codeforces Round #501 (Div. 3) D. Walking Between Houses
    Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
    “字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛 1010 Count
    Educational Codeforces Round 32 E. Maximum Subsequence
    Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field 数学
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6480016.html
Copyright © 2011-2022 走看看