zoukankan      html  css  js  c++  java
  • poj 3660 Cow Contest Flyod

    题目链接:

    http://poj.org/problem?id=3660

    题意:

    给出牛之间的强弱关系,让你确定有多少头牛能够确定其排名。

    题解:

    就是求出每个点的入度和出度的和,如果是n-1,就可以确定排名
    floyd

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 typedef long long ll;
     6 #define MS(a) memset(a,0,sizeof(a))
     7 #define MP make_pair
     8 #define PB push_back
     9 const int INF = 0x3f3f3f3f;
    10 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
    11 inline ll read(){
    12     ll x=0,f=1;char ch=getchar();
    13     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    14     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    15     return x*f;
    16 }
    17 //////////////////////////////////////////////////////////////////////////
    18 const int maxn = 1e5+10;
    19 
    20 int g[105][105];
    21 
    22 int main(){
    23     int n=read(), m=read();
    24     for(int i=1; i<=m; i++){
    25         int u,v; scanf("%d%d",&u,&v);
    26         g[u][v] = 1;
    27     }
    28 
    29     for(int k=1; k<=n; k++)
    30         for(int i=1; i<=n; i++)
    31             for(int j=1; j<=n; j++)
    32                 if(g[i][k]&&g[k][j])
    33                     g[i][j] = 1;
    34 
    35     int ans = 0;
    36     for(int i=1; i<=n; i++){
    37         int cnt = 0;
    38         for(int j=1; j<=n; j++){
    39             if(g[i][j] || g[j][i])
    40                 cnt++;
    41         }
    42         // cout << cnt << endl;
    43         if(cnt == n-1)
    44             ans++;
    45     }
    46 
    47     printf("%d
    ",ans);
    48 
    49     return 0;
    50 }
  • 相关阅读:
    oracle,mysql对敏感,关键字等处理
    eclipse内置tomcat启动方法
    plsql登录弹白框
    date
    linux乱码
    环境变量
    终端类型
    netstat -aon|findstr 8888 终止进程
    export
    bash环境变量读取顺序
  • 原文地址:https://www.cnblogs.com/yxg123123/p/6827644.html
Copyright © 2011-2022 走看看