POJ - 3660Cow Contest

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 .
给几对牛AB,A比B强,求最多确定几头牛的排名。
当给出这样的关系时,排名被确定的牛至少有一头,这个很容易想出。
当图中某头牛与所有牛都能有关系时,他的排名也就被确定了(因为他与排名被确定的牛的关系确定了,可推到出自己排名)
用Floyd算法
无脑贴模板…….

#include<iostream>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string>
using namespace std;
#define N 100+5
#define LL long long int
#define pow(a) ((a)*(a))
#define INF 0x3f3f3f3f
#define mem(arr,a) memset(arr,a,sizeof(arr))
int n, m;
int cost[N][N];
bool judge(int x){
    for (int i = 1; i <= n; i++){
        if (cost[i][x] != INF || cost[x][i] != INF)continue;
        return 0;
    }
    return 1;

}
int main(){
    cin >> n >> m;
    mem(cost, INF);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        cost[a][b] = 1;

    }
    for (int i = 1; i <= n; i++)cost[i][i] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            for (int k = 1; k <= n; k++){
                cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
            }
        }
    }
    cost;
    int MAX = 0;
    for (int i = 1; i <= n; i++){
        if (judge(i))MAX++;
    }
    cout<<MAX<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值