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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1); int g[105][105],n,m; void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(g[j][k]&&g[k][i])
g[j][i]=1;
} int main()
{
while(~scanf("%d %d",&n,&m))
{
MM(g,0);
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d %d",&x,&y);
g[y][x]=1;
}
floyd();
int ans=0;
for(int i=1;i<=n;i++)
{
int temp=0;
for(int j=1;j<=n;j++)
temp+=g[i][j]+g[j][i];
if(temp==n-1) ans++;
}
printf("%d\n",ans);
}
return 0;
}

  分析:

1.一头牛的排名能确定的话,那么肯定他跟其余的n-1头牛的胜负关系都已经(直接或间接)确定好了,因此,只需判断这头牛是否与其他牛的胜负关系确定了没有。

2.A输给了B,B输给了C,那么A肯定会输给C,要确定任意两头牛之间的胜负关系,可以使用Floyd,注意

Floyd不仅可以确定任意两点之间的最短路径,还可以确定出他们之间的相对关系,同样是通过最外面一层循环的更新思想实现。

POJ 3660 Cow Contest 任意两点之间的关系 Floyd的更多相关文章

  1. POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )

    题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A  B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...

  2. POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)

    POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...

  3. POJ 3660 Cow Contest (floyd求联通关系)

    Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...

  4. POJ 3660 Cow Contest 传递闭包+Floyd

    原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  5. POJ 3660 Cow Contest

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  6. (中等) POJ 3660 Cow Contest,Floyd。

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  7. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  8. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  9. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

随机推荐

  1. PTA(Basic Level)1061.判断题

    判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分. 输入格式: 输入在第一行给出两个不超过 100 的正整数 N 和 M,分别是学生人数和判断题数量.第二行给出 M ...

  2. Python流程控制与while 循环(day01)

    一:流程控制 假如把写程序比做走路,那我们到现在为止,一直走的都是直路,还没遇到过分叉口,想象现实中,你遇到了分叉口,然后你决定往哪拐必然是有所动机的.你要判断哪条叉路是你真正要走的路,如果我们想让 ...

  3. 小记-------linux scp 远程拷贝命令

    //phoenix-4.10.0-HBase-1.2-server.jar  要拷贝的文件或文件夹 //root  当前用户   //192.148.21.1 远程机器路径, 也可以是域名. // $ ...

  4. centos 7下nginx搭建流媒体服务器【动态添加模块】

    1.安装nginx依赖包 yum install gcc gcc-c++ openssl-devel zlib-devel pcre pcre-devel yamdi 2.下载解压nginx_mod_ ...

  5. k路归并

    public static int[] k_merge(ArrayList<int[]> k_array) { if(CollectionUtils.isEmpty(k_array)){ ...

  6. redis远程连接配置

    解决redis远程连接不上的问题 redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的 ...

  7. curry&unCurry函数

    unCurry函数与curry函数区别:curry化函数:固定部分参数,返回一个接受剩余参数的新函数,目的是为了缩小适用范围,创建一个针对性更强的函数. unCurry化函数:扩大适用范围,创建一个应 ...

  8. mysql登录密码错误,以及设置密码

    1.输了几次,密码都错误,忘记了... 2.编辑mysql安装文件夹(D:\mysql-5.7.26-winx64)下的my.ini文件,mysqld标签下输入 skip-grant-tables,字 ...

  9. unittest assert断言

    unittest常用的断言方法 1.assertEqual(self, first, second, msg=None) --判断两个参数相等:first == second 2.assertNotE ...

  10. 2019-11-29-C#-在-8.0-对比-string-和-string_-的类型

    title author date CreateTime categories C# 在 8.0 对比 string 和 string? 的类型 lindexi 2019-11-29 8:59:0 + ...