这题主要是传递闭包

题意: n头牛,m次测试,假设a牛赢过b牛,那么说明a牛的能力比b牛强,问你根据输入的m次测试结果,最多能确定多少条牛的排名

大题的思路:

  对于 k 牛,比他强的有x头牛,比他弱的有y头牛,只要x+y == n-1,那么x的排名就能确定

  也就是求任意两头牛之间能否到达

  每次测试都能加入一条新的边,用floyd求任意两点间能否抵达

  最后根据比他强和比他弱的个数求和等于n-1说明这头牛能确定排名

  。。。。。。

有点小细节:这个题假设a牛能胜过b牛,代表的是能力值高低,我们也是只要求确定能力值的排名,所以a牛赢过b牛,b牛赢过c牛,那么a牛一定能赢过c牛,c牛不可能赢过a牛

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int dis[][];
void flo(int n);
int main()
{
int n,m;
while(scanf("%d%d",&n,&m) != EOF)
{
memset(dis,,sizeof(dis));
while(m--)
{
int a,b;
scanf("%d %d",&a,&b);
dis[a][b] = ;
}
flo(n);
int ans = ;
for(int i = ; i <= n; ++i)
{
int c = ; for(int j = ; j <= n; ++j)
{
if(dis[i][j] == || dis[j][i]) c ++;
}
if(c == n-) ans ++;
}
cout << ans << endl;
}
}
void flo(int n)
{
for(int k = ; k <= n; ++k)
{
for(int i = ; i <= n; ++i)
{
for(int j = ; j <= n; ++j)
{
          //dis[i][i] 一定等于0 不用i==j continue
if(dis[i][k] == && dis[k][j] == )
dis[i][j] = ;
}
}
}
}

poj3660 cow contest的更多相关文章

  1. POJ3660——Cow Contest(Floyd+传递闭包)

    Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...

  2. POJ-3660.Cow Contest(有向图的传递闭包)

      Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 De ...

  3. POJ3660:Cow Contest(Floyd传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接 ...

  4. POJ3660 Cow Contest —— Floyd 传递闭包

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

  5. POJ3660 Cow Contest floyd传递闭包

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

  6. POJ3660 Cow Contest【最短路-floyd】

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  7. POJ-3660 Cow Contest( 最短路 )

    题目链接:http://poj.org/problem?id=3660 Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, ar ...

  8. poj3660 Cow Contest(Floyd-Warshall方法求有向图的传递闭包)

    poj3660 题意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 分析: 在这呢先说一下关系闭包: 关系闭包有三种: 自反闭包(r), 对 ...

  9. poj3660(Cow Contest)解题报告

    Solution: 传递闭包 //if a beats b and b beats c , then a beats c //to cow i, if all the result of conten ...

  10. POJ-3660 Cow Contest Floyd传递闭包的应用

    题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...

随机推荐

  1. PhoenixFD插件流体模拟——UI布局【Interaction】详解

    流体交互 本文主要讲解Interaction折叠栏中的内容.原文地址:https://docs.chaosgroup.com/display/PHX3MAX/Liquid+Interaction 主要 ...

  2. splice的用法

    splice向数组中删除/添加新元素,然后返回新数组 arrObject.splice(index,howmany,item1,...,itemx); 参数 描述 index 必需.整数,规定添加/删 ...

  3. python 获取随机字母

    Python2 #-*- coding:utf- -*- import string #导入string这个模块 print string.digits #输出包含数字0~9的字符串 print st ...

  4. 在进行商业运算时解决BigDecimal的精度丢失问题

    System.out.println(0.05+0.01); System.out.println(1.0-0.42); System.out.println(4.015*100); System.o ...

  5. redis设置密码

    1.初始化Redis密码: 在redis.conf配置文件中有个参数: requirepass  这个就是配置redis访问密码的参数: 比如 requirepass test123: (Ps:需重启 ...

  6. 20175126《Java程序设计》第八周学习总结

    # 20175126 2016-2017-2 <Java程序设计>第八周学习总结 ## 教材学习内容总结 - 本周学习方式主要为手动敲代码并理解内容学习. - 学习内容为教材第十五章,本章 ...

  7. idea 用tomcat运行javaWeb

    指定tomcat在计算机的安装位置: 给项目加一个启动配置: 添加一个本地tomcat: 配置这个本地tomcat: 运行方面:

  8. php-fpm重启

    Ubuntu 18.04服务器 修改php init 文件后(/etc/php/7.2/fpm/php.ini)需要重启php-fpm,方法是: kill -USR2 `cat /run/php/ph ...

  9. .gitinore配置失效问题

    问题:在.gitinore中配置忽略项,配置失效 原因:新增加忽略项已经提交过,在暂存区或分支上被版本控制 解决:删除暂存区或分支上的文件(本地需要使用, 只是不希望这个文件被版本控制), 可以使用 ...

  10. mysql学习记录

    干净卸载mysql:https://blog.csdn.net/cxy_summer/article/details/70142322mysql 解压缩版安装说明:https://jingyan.ba ...