• 【图论】牛大赛


    原题传送门

    思路


    这道题其实不难,主要难在不好判断有哪些奶牛的排名可以确定,但这个问题其实非常好解决:入度+出度=N-1的奶牛都可以确定,反之不可以确定。
    然后,若奶牛i能打败奶牛k,而奶牛k可以打败奶牛j,那么,奶牛i一定可以打败奶牛j(这不是废话吗)。
    只要来一波无脑Floyd,确定每一个节点的出度数和入度数即可。

    说句题外话,国外的题要不要这么搞⛏?奶牛开编程大赛,为毛我感觉讽刺意味好浓呢QAQ?

    Code


    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<vector>
    #include<algorithm>
    #include<cstdlib>
    #define int long long
    using namespace std;
    
    int G[101][101];
    int N,M,A,B,ans,tans;
    
    signed main()
    {
        scanf("%ld%ld",&N,&M);
        for(int i=1;i<=M;i++)
        {
        	scanf("%ld%ld",&A,&B);
        	G[A][B]=1;
    	}
        for(int k=1;k<=N;k++)
        	for(int i=1;i<=N;i++)
        		for(int j=1;j<=N;j++)
        			if(G[i][k]&&G[k][j])
        				G[i][j]=1;
        for(int i=1;i<=N;i++)
        {
        	tans=0;
        	for(int j=1;j<=N;j++)
        	{
        		tans+=G[i][j]+G[j][i];
    		}
    		if(tans==N-1)
    		{
    			ans++;
    		}
    	}
    	printf("%d",ans);
        return 0;
    }
    
  • 相关阅读:
    Three Algorithms for Fibonacci
    微软面试经历
    [TIP]命令行快速查看图片(Ubuntu)
    emacs as the c++ ide on the Ubuntu
    boost learn notes
    ReadingNotes@02122013
    ignoreunderline.org
    cnblogsminormode.org
    c++ 0x 新特性
    noip模拟赛 思考熊的马拉松
  • 原文地址:https://www.cnblogs.com/gongdakai/p/11265861.html
Copyright © 2020-2023  润新知