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.tie(0);
14     memset(mp, 0, sizeof(mp));
15     cin >> n >> m;
16     for(int i = 0;i < m;i++){
17         int  x, y;
18         cin >> x >> y;
19         mp[x][y] = 1;
20         mp[y][x] = -1;
21     }
22
23     for(int i = 1;i <= n;i++){
24         for(int j = 1;j <= n;j++){
25             for(int k = 1;k <= n;k++){
26                 if(mp[j][i] == mp[i][k] && mp[j][i] != 0){
27                     mp[j][k] = mp[j][i];
28                 }
29             }
30         }
31     }
32     int ans = 0;
33     for(int i = 1;i <= n;i++){
34         int sum = 0;
35         for(int j = 1;j <= n;j++){
36             if(mp[i][j] != 0){
37                 sum++;
38             }
39         }
40         if(sum == n-1){
41             ans++;
42         }
43     }
44     cout << ans << endl;
45
46     return 0;
47 }
floyed

原文地址:https://www.cnblogs.com/jaydenouyang/p/9021462.html

时间: 2024-08-30 18:22:00

H - Cow Contest的相关文章

[USACO08JAN]牛大赛Cow Contest

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

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

[bzoj1612][Usaco2008 Jan]Cow Contest奶牛的比赛_dfs

Cow Contest奶牛的比赛 bzoj-1612 Usaco-2008 Jan 题目大意:题目链接. 注释:略. 想法: 我们对于每个点dfs,看一下比这个点大的点加上比这个点小的点是否是n-1即可. 最后,附上丑陋的代码... ... #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N

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

P2419 [USACO08JAN]牛大赛Cow Contest

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

POJ-3660.Cow Contest(有向图的传递闭包)

Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 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 other

牛大赛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 competito

POJ-3660 Cow Contest

Problem 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 competitors. Th