[kuangbin]专题四 最短路练习 Cow Contest POJ - 3660【传递闭包】

【题目描述】
N (1 ≤ N ≤ 100) cows, conveniently numbered 1…N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.
N(1≤N≤100)头奶牛,编号为1…N,正在参加编程竞赛。 众所周知,有些奶牛敲代码比其他奶牛更强。 每头奶牛都有一定的技能等级,这在竞争对手中是独一无二的。
The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ B), then cow A will always beat cow B.
比赛是在几个头对头的比赛中进行的,每轮比赛都在两头奶牛之间进行。 如果母牛A的技能水平高于母牛B(1≤A≤N;1≤B≤N; A≠B),那么母牛A将始终击败母牛B.
Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.
农夫约翰试图按技能水平对奶牛进行排名。 给出M(1≤M≤4,500)对牛的结果列表,确定可以从结果中确定奶牛的等级的数量。 保证轮次的结果不会相互矛盾。

【输入】
* Line 1: Two space-separated integers: N and M
* Lines 2…M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B
*第1行:两个以空格分隔的整数:N和M.
*第2行… M + 1:每一行包含两个以空格分隔的整数,用于描述竞争对手和单轮竞赛的结果(第一个整数,A,是赢家):A和B

【输出】
* Line 1: A single integer representing the number of cows whose ranks can be determined
*第1行:一个整数,表示可以确定等级的奶牛数量

【样例输入】
5 5
4 3
4 2
3 2
1 2
2 5

【样例输出】
2

题目链接:https://cn.vjudge.net/problem/POJ-3660

floyd实现传递闭包

代码如下:

#include <iostream>
using namespace std;
static const int MAXN=100;
int E[MAXN+10][MAXN+10];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        E[i][i]=1;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        E[x][y]=1;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                E[i][j]|=E[i][k]&E[k][j];
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int cnt=0;
        for(int j=1;i<=n;j++)
        {
            if(E[i][j] | E[j][i])
                cnt++;
            else
                break;            
        }
        if(cnt==n)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值