zoukankan      html  css  js  c++  java
  • hdu1704:Rank

    Problem Description
    there are N ACMers in HDU team.
    ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellent ACMers to attend the contest. There have been M matches since the last few days(No two ACMers will meet each other at two matches, means between two ACMers there will be at most one match). lcy also asks"Who is the winner between A and B?" But sometimes you can't answer lcy's query, for example, there are 3 people, named A, B, C.and 1 match was held between A and B, in the match A is the winner, then if lcy asks "Who is the winner between A and B", of course you can answer "A", but if lcy ask "Who is the winner between A and C", you can't tell him the answer.
    As lcy's assistant, you want to know how many queries at most you can't tell lcy(ask A B, and ask B A is the same; and lcy won't ask the same question twice).
     
    Input
    The input contains multiple test cases.
    The first line has one integer,represent the number of test cases.
    Each case first contains two integers N and M(N , M <= 500), N is the number of ACMers in HDU team, and M is the number of matchs have been held.The following M lines, each line means a match and it contains two integers A and B, means A wins the match between A and B.And we define that if A wins B, and B wins C, then A wins C.
     
    Output
    For each test case, output a integer which represent the max possible number of queries that you can't tell lcy.
     
    Sample Input
    3 3 3 1 2 1 3 2 3 3 2 1 2 2 3 4 2 1 2 3 4
     
    Sample Output
    0 0 4
     
    题解
    floyd求传递闭包裸题,传递性:a<b,b<c,则a<c。
    传递闭包请自行百度。
     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 #define maxn 505
     5 using namespace std;
     6 int n,m,cnt;
     7 int link[maxn][maxn];
     8 void Floyd()
     9 {
    10     for(int k=1 ; k<=n ; ++k )
    11         for(int i=1 ; i<=n ; ++i )
    12                 if(link[i][k])
    13                     for(int j=1 ; j <= n ; ++j)
    14                         if(link[k][j])
    15                             link[i][j]=1;
    16 }
    17 void init()
    18 {
    19     cnt=0;
    20     memset(link,0,sizeof(link));
    21 }
    22 int main()
    23 {
    24     int t,u,v;
    25     scanf("%d",&t);
    26     while(t--)
    27     {
    28         init();
    29         scanf("%d%d",&n,&m);
    30         for(int i=1 ; i<=m ; ++i )
    31             {
    32                 scanf("%d%d",&u,&v);
    33                 link[u][v]=1;
    34             }
    35         for(int i=1 ; i<=n ; ++i)link[i][i]=1;
    36         Floyd();
    37         for(int i=1 ; i<=n ; ++i )
    38             for(int j=i+1 ; j<=n ; ++j )
    39                 if(!(link[i][j]||link[j][i]))cnt++;
    40         printf("%d
    ",cnt);
    41     }
    42     return 0;
    43  } 
  • 相关阅读:
    PHP post接口返回数据
    wamp 安装多版本php
    关于WAMP的apache 人多了就访问非常卡的问题解决方法(转)
    在生产环境上重装wamp
    wamp不记录访问日志的办法
    oracle数据库锁表解决办法
    wampserver 中127.0.0.1可以访问,但localhost无法访问
    PLSQL中查询数据的时候查询结果显示中文乱码(转)
    Could not read from remote repository
    17-案例
  • 原文地址:https://www.cnblogs.com/fujudge/p/7496795.html
Copyright © 2011-2022 走看看