【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 #include<iostream>
 5 using namespace std;
 6
 7 const int maxn = 110;
 8 const int inf = 1e9;
 9 int n,m;
10 int mp[maxn][maxn];
11
12 void floyd(){
13     for(int k = 1; k <= n ; k++){
14         for(int i = 1; i <= n ;i++){
15             for(int j = 1; j <= n ;j++){
16                 if(mp[i][j] == 1 || (mp[i][k] == 1 && mp[k][j] == 1) ){
17                     mp[i][j] = 1;
18                 }
19             }
20         }
21     }
22
23 }
24
25 int main(){
26     cin>>n>>m;
27     for( int i = 1; i <= m ;i++){
28         int x,y;
29         cin>>x>>y;
30         mp[x][y] = 1;
31     }
32     floyd();
33     int ans = 0;
34     for(int i = 1; i <= n ;i++){
35         int cnt = 0;
36         for(int j = 1; j <= n; j++){
37             if(i == j)
38                 continue;
39             if(mp[i][j] == 1 || mp[j][i] == 1){
40                 cnt++;
41             }
42         }
43         if(cnt == n-1)
44             ans++;
45     }
46     cout<<ans<<endl;
47     return 0;
48 }

原文地址:https://www.cnblogs.com/Asumi/p/9740774.html

时间: 2024-07-29 17:40:49

【POJ】3660 Cow Contest的相关文章

【POJ】3270.Cow Sorting

题解 用到一点群论的知识! 我们发现把操作写成一个置换后,一定是单个置换圈的内进行操作,把置换圈进行扩大的操作不优 我们有两个办法,一个是用全局最小的换进来,代替这个圈里最小的值,交换操作完成后再换出去,二是用圈里最小的换完一圈 就两个操作,计算后贪心即可 代码 #include <iostream> #include <cstdio> #include <vector> #include <set> #include <cstring> #in

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

【POJ】2528 Mayor&#39;s posters ——离散化+线段树

Mayor's posters Time Limit: 1000MS    Memory Limit: 65536K Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city

【POJ】 Instant Complexity (模拟)

[POJ] Instant Complexity (模拟) Instant Complexity Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1905   Accepted: 657 Description Analyzing the run-time complexity of algorithms is an important tool for designing efficient programs that

【POJ】3264 Balanced Lineup ——线段树 区间最值

Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34140   Accepted: 16044 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh

【POJ】2278 DNA Sequence

各种wa后,各种TLE.注意若AC非法,则ACT等一定非法.而且尽量少MOD. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 using namespace std; 6 7 #define MAXN 105 8 #define NXTN 4 9 10 char str[15]; 11 12 typedef struct Matrix {

【HDOJ】3660 Alice and Bob&#39;s Trip

就是一个基本的dfs.可关键问题是c/c++/g++光输入就超时了.还是写java过的,毕竟时限4s.都放弃希望了,没想到还真过了. 1 import java.lang.*; 2 import java.io.*; 3 import java.util.*; 4 5 6 public class Main { 7 8 public static void main(String[] args) throws java.lang.Exception { 9 InputStream inputSt

【POJ】1739 Tony&#39;s Tour

http://poj.org/problem?id=1739 题意:n×m的棋盘,'#'是障碍,'.'是空白,求左下角走到右下角且走过所有空白格子的方案数.(n,m<=8) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; #define BIT(a,b) ((a)<<((b)<<1)) #

【POJ】2449 Remmarguts&#39; Date(k短路)

http://poj.org/problem?id=2449 不会.. 百度学习.. 恩. k短路不难理解的. 结合了a_star的思想.每动一次进行一次估价,然后找最小的(此时的最短路)然后累计到k 首先我们建反向边,跑一次从汇到源的最短路,将跑出来的最短路作为估价函数h 根据f=g+h 我们将源s先走,此时实际价值g为0,估价为最短路(他们的和就是s-t的最短路) 将所有s所连的边都做相同的处理,加入到堆中(假设此时到达的点为x,那么x的g等于s到这个点的边权,因为根据最优,g+h此时是从x