牛大赛Cow Contest

题目背景

[Usaco2008 Jan]

题目描述

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.

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.

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.

FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:)。在赛场上,奶牛们按1..N依次编号。每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名。 整个比赛被分成了若干轮,每一轮是两头指定编号的奶牛的对决。如果编号为A的奶牛的编程能力强于编号为B的奶牛(1 <= A <= N; 1 <= B <= N; A != B) ,那么她们的对决中,编号为A的奶牛总是能胜出。 FJ想知道奶牛们编程能力的具体排名,于是他找来了奶牛们所有 M(1 <= M <= 4,500)轮比赛的结果,希望你能根据这些信息,推断出尽可能多的奶牛的编程能力排名。比赛结果保证不会自相矛盾。

输入格式

第1行: 2个用空格隔开的整数:N 和 M

第2..M+1行: 每行为2个用空格隔开的整数A、B,描述了参加某一轮比赛的奶 牛的编号,以及结果(编号为A,即为每行的第一个数的奶牛为 胜者)

输出格式

第1行: 输出1个整数,表示排名可以确定的奶牛的数目

输入输出样例

输入 #1复制

5 5
4 3
4 2
3 2
1 2
2 5

输出 #1复制

2

说明/提示

输出说明:

编号为2的奶牛输给了编号为1、3、4的奶牛,也就是说她的水平比这3头奶

牛都差。而编号为5的奶牛又输在了她的手下,也就是说,她的水平比编号为5的

奶牛强一些。于是,编号为2的奶牛的排名必然为第4,编号为5的奶牛的水平必

然最差。其他3头奶牛的排名仍无法确定。

f[i][j]=f[i][j]|(f[i][k]&f[k][j])表示i能否走到j,即要么一开始i能到j,要么i能到k,k再能到j。

那么这里表示的是i能否赢j。用floyed求出每个点与个点的关系,只要这个点和其他

n-1个点的关系都确定了,就能确定他的排名。

#include<cstdio>
using namespace std;

int n,m,i,j,k,f[205][205],x,y,ans=0;

int main(){
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d%d",&x,&y);
        f[x][y]=1;
    }
    for(k=1;k<=n;k++){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                f[i][j]=f[i][j]|f[i][k]&f[k][j];
            }
        }
    }
    for(i=1;i<=n;i++){
        int ch=1;
        for(j=1;j<=n;j++){
            if(i==j){
                continue;
            }
            ch=ch&(f[i][j]|f[j][i]);
        }
        ans+=ch;
    }
    printf("%d",ans);
    return 0;
}

原文地址:https://www.cnblogs.com/hrj1/p/11161257.html

时间: 2024-11-01 17:19:51

牛大赛Cow Contest的相关文章

P2419 [USACO08JAN]牛大赛Cow Contest

P2419 [USACO08JAN]牛大赛Cow Contest 海星 这题代码比较短 (哪题Floyd代码长的) 太真实了 直接上代码吧 这题就是一个经典的传递闭包问题 可以用拓扑排序啥的 不过还是Floyd简便一下 原文地址:https://www.cnblogs.com/qf-breeze/p/10473684.html

[USACO08JAN]牛大赛Cow Contest

题目链接: Cow Contest 分析: 听说是一个Floyd求传递闭包 被拓扑的标签骗了进去 首先如果整个图不连通那么显然没办法确定,因为两个连通块之间的信息没有办法传递 所以先并查集判一下 然后考虑拓扑排序,一个点能得到确定的排名当且仅当它能被之前所有入过队的点到达 代码: #include<bits/stdc++.h> #define N (300 + 10) #define M (50000 + 10) using namespace std; inline int read() {

Luogu P2419 [USACO08JAN]牛大赛Cow Contest

传递闭包板子,震惊自己之前居然没学过,特此记录一下. #include <bits/stdc++.h> using namespace std; const int N = 110; int n, m, u, v, to[N][N]; int main () { cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> u >> v; to[u][v] = true; } for (int k

ACM: POJ 3660 Cow Contest - Floyd算法

链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description 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. Eac

poj 3660 Cow Contest(warshall算法)

poj 3660 Cow Contest Description 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 co

POJ3660:Cow Contest(Floyd传递闭包)

Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接:http://poj.org/problem?id=3660 Description: N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all k

洛谷P3045 [USACO12FEB]牛券Cow Coupons

P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 86分求救 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget

洛谷 P3014 [USACO11FEB]牛线Cow Line

P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The cows will arrange themselves in a line and ask Far

洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N cows jogging on an infinitely-long single-lane track (1 <= N <= 100,000). Each cow starts at a distinct position on the track, and some cows jog at