POJ 3360 H-Cow Contest

http://poj.org/problem?id=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.

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 ≤ NA ≠ 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.

Input

* 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

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined
 

Sample Input

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

Sample Output

2

题解:$floyd$ 算法 如果赢过的人加上败给的人的和是 $N - 1$ 就是可以确定位置的人

代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;

int N, M;
int mp[110][110];

void floyd() {
    for(int k = 1; k <= N; k ++) {
        for(int i = 1; i <= N; i ++) {
            if(mp[i][k])
            for(int j = 1; j <= N; j ++) {
                if(mp[k][j] == 1 && mp[i][k] == 1) {
                    mp[i][j] = 1;
                    mp[j][i] = -1;
                }
                else if(mp[k][j] == -1 && mp[i][k] == -1) {
                    mp[i][j] = -1;
                    mp[j][i] = 1;
                }
                else continue;
            }
        }
    }
}

int main() {
    memset(mp, 0, sizeof(mp));
    scanf("%d%d", &N, &M);
    for(int i = 1; i <= M; i ++) {
        int a, b;
        scanf("%d%d", &a, &b);
        mp[a][b] = 1;
        mp[b][a] = -1;
    }

    floyd();
    int ans = 0;
    for(int i = 1; i <= N; i ++) {
        int sum = 0;
        for(int j = 1; j <= N; j ++)
            if(mp[i][j])
                sum ++;

        if(sum == N - 1)
            ans ++;
    }
    printf("%d\n", ans);
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9895713.html

时间: 2024-08-30 17:06:44

POJ 3360 H-Cow Contest的相关文章

【POJ】3660 Cow Contest

题目链接:http://poj.org/problem?id=3660 题意:n头牛比赛,有m场比赛,两两比赛,前面的就是赢家.问你能确认几头牛的名次. 题解:首先介绍个东西,传递闭包,它可以确定尽可能多的元素之间的关系. 然后回到这道题,怎么能确认这头牛的名次,也就是不管它胜还是败都能推导出其他n-1头牛跟它的关系.具体思想看代码.QWQ 代码: 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4

H - Cow Contest

1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <cstring> 5 using namespace std; 6 7 int n, m; 8 const int maxn = 105; 9 int mp[maxn][maxn]; 10 11 int main(){ 12 ios_base::sync_with_stdio(false); 13 cin.

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

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 3268 Silver Cow Party(SPFA)

Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i re

POJ 3189 Steady Cow Assignment(网络流之最大流+二分构图)

题目地址:POJ 3189 我晕啊...飞快的把白天的任务完成又有什么用...节省下来的时间活生生的被我的手残给全浪费掉了...又调了一整天,问题居然是一个地方的n和m写反了!!!反思..反思...面壁去... 这题就是二分区间,然后枚举区间位置.然后建图就行了.不多说.. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include

POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects

POJ 3623 Best Cow Line, Gold(模拟)

题意  给你一个字符序列   你每次可以从它的头部或尾部拿出一个字符组成一个新的字符序列   输出这样做能达到的最小的字符序列   每行最多输出80个字符(开始被这个坑了好久) 直接模拟就行  哪边小就选哪边  相等就往内看 #include<cstdio> #include<iostream> #include<string> using namespace std; const int N = 30010; int main() { char s[N][2]; in

poj 3617 Best Cow Line (字符串反转贪心算法)

Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9284   Accepted: 2826 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his

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