zoukankan      html  css  js  c++  java
  • 【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 }
  • 相关阅读:
    图像修补
    图像的矩
    使用多边形将轮廓包围
    寻找物体的凸包
    查找并绘制轮廓
    重映射
    霍夫变换
    边缘检测
    第二周神经网络基础
    第一周:深度学习引言(Introduction to Deep Learning)
  • 原文地址:https://www.cnblogs.com/Asumi/p/9740774.html
Copyright © 2011-2022 走看看