1. 程式人生 > >POJ-3660-Cow Contest

POJ-3660-Cow Contest

scanf ems \n cow clu 1-1 vector test algorithm

鏈接:https://vjudge.net/problem/POJ-3660

題意:

有N個牛(1-100),兩兩對決M次(1-2500)。

得到一個結果。求能準確確定名次的牛的個數。

思路:

一頭牛可以被a頭牛擊敗,同時擊敗b頭牛時,這頭牛的名次確定。

Floyd算法。

代碼:

#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
const int MAXN = 100+10;
int Map[MAXN][MAXN];
int win[MAXN],lose[MAXN];
int n,m;

void Floyd()
{
    for (int i = 1;i<=n;i++)
        for (int j = 1;j<=n;j++)
            for (int k = 1;k<=n;k++)
                if (Map[j][i] == 1&&Map[i][k] == 1)
                    Map[j][k] = 1;
}

int main()
{
    scanf("%d%d",&n,&m);
    int l,r;
    memset(Map,0,sizeof(Map));
    for (int i = 1;i<=m;i++)
    {
        scanf("%d%d",&l,&r);
        Map[l][r] = 1;
    }
    Floyd();
    for (int i = 1;i<=n;i++)
        for (int j = 1;j<=n;j++)
        {
            if (Map[i][j] == 1)
            {
                win[i]++;
                lose[j]++;
            }
        }
    int sum = 0;
    for (int i = 1;i<=n;i++)
        if (win[i]+lose[i] == n-1)
            sum++;

    printf("%d\n",sum);

    return 0;
}

  

POJ-3660-Cow Contest