zoukankan      html  css  js  c++  java
  • poj 3660 Cow Contest

    Cow Contest
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 8987   Accepted: 5046

    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.

    The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ NA ≠ B), then cow A will always beat cow B.

    Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.

    Input

    * Line 1: Two space-separated integers: N and M
    * Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B

    Output

    * Line 1: A single integer representing the number of cows whose ranks can be determined
     

    Sample Input

    5 5
    4 3
    4 2
    3 2
    1 2
    2 5
    

    Sample Output

    2

    可以说得上是最短路吧,反正我会是用弗洛伊德暴力水过的,代码很简单,思路清晰就好。

    题意:牛之间有绝对的强弱,给出一些胜负关系,问有多少头牛可以确定其绝对排名。

    附上代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,m,i,j,k;
     8     while(~scanf("%d%d",&n,&m))
     9     {
    10         int a,b,map[105][105],t;
    11         memset(map,0,sizeof(map));
    12         for(i=1; i<=m; i++)
    13         {
    14             scanf("%d%d",&a,&b);
    15             map[a][b]=1;
    16         }
    17         for(i=1; i<=n; i++)
    18             for(j=1; j<=n; j++)
    19                 for(k=1; k<=n; k++)
    20                     if(map[j][i]&&map[i][k])  //暴力弗洛伊德,所有的关系连成图
    21                         map[j][k]=1;
    22         int ans=0;
    23         for(i=1; i<=n; i++)
    24         {
    25             int t=0;
    26             for(j=1; j<=n; j++)
    27                 t+=map[i][j]+map[j][i];
    28             if(t==n-1)
    29                 ans++;
    30         }
    31         printf("%d
    ",ans);
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    python--输出spwm的数组
    爬虫二:爬取糗事百科段子
    爬虫一:爬取信息
    Python中的切片操作
    JSON
    python 中的异常处理与种类
    register的功能
    static的功能
    网络安全的认识
    VMware5.5-vCenter Converter(转换)
  • 原文地址:https://www.cnblogs.com/pshw/p/5247775.html
Copyright © 2011-2022 走看看