zoukankan      html  css  js  c++  java
  • hdu 1704 Rank (floyd闭包)

    Rank

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1630    Accepted Submission(s): 627


    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
    Hint
    in the case3, if lcy ask (1 3 or 3 1) (1 4 or 4 1) (2 3 or 3 2) (2 4 or 4 2), then you can't tell him who is the winner.
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1703 1700 1701 1706 1705 
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 
     6 using namespace std;
     7 
     8 int a[505][505];
     9 int t,n,m;
    10 
    11 void floyd(){
    12     for(int i=1;i<=n;i++){
    13         for(int j=1;j<=n;j++){
    14             if(a[j][i]==0){continue;}
    15             for(int k=1;k<=n;k++){
    16                 a[j][k]=a[j][k]||a[j][i]&a[i][k];
    17             }
    18         }
    19     }
    20 }
    21 
    22 int main()
    23 {
    24     scanf("%d",&t);
    25     while(t--){
    26         scanf("%d %d",&n,&m);
    27         int t1,t2;
    28         int sum=0;
    29         memset(a,0,sizeof(a));
    30         for(int i=0;i<m;i++){
    31             scanf("%d %d",&t1,&t2);
    32             a[t1][t2]=1;
    33         }
    34         floyd();
    35         for(int i=1;i<=n;i++){
    36             for(int j=1;j<=n;j++){
    37                 if(a[i][j]!=0){
    38                     sum++;
    39                 }
    40             }
    41         }
    42         printf("%d
    ",(n*n-n)/2-sum);
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    Vue2 组件注册
    Vue2 CSS 过渡
    Vue2 过滤器
    Vue2 路由
    网页一次滚动一屏幕效果
    JavaScript作用域-声明提升(个人总结)
    JS函数作用域提升
    如何以计算机的方式去思考
    常用Git命令总结
    关于RBAC(Role-Base Access Control)的理解(转)
  • 原文地址:https://www.cnblogs.com/TWS-YIFEI/p/6765238.html
Copyright © 2011-2022 走看看