码迷,mamicode.com
首页 > 其他好文 > 详细

【POJ】3660 Cow Contest

时间:2018-10-04 10:51:40      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:targe   ios   ble   比赛   i++   code   mes   class   font   

题目链接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 }

 

【POJ】3660 Cow Contest

标签:targe   ios   ble   比赛   i++   code   mes   class   font   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!