这题主要是传递闭包

题意: 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. 【MYSQL】MYSQLの環境構築

    ダウンロード:https://dev.mysql.com/downloads/mysql/ 手順① 手順② mysql.iniの設定について [mysql]default-character-set= ...

  2. Mybatis 接口代理的实现(BeanDefinitionRegistryPostProcessor+FactoryBean)

    相信在开发中,尤其是mybatis 配置操作中,我们只需要提供一个mapper 接口,然后注入到service 中,就可以进行调用. 按我们的一般逻辑来说,我们并没有进行接口的实现,应该会报空指针异常 ...

  3. Putty6.0 提示Access denied

    1.如果putty能正常使用,解决方法很简单: 只要在Putty的configuration里面Connection->SSH->Auth->GSSAPI的配置中,去掉默认的Atte ...

  4. MySQL:缓存算什么东西?!

    原创: 码农翻身刘欣 十年前,我们还是一个企业内部的应用,用户不多,数据也不多. Tomcat一天也处理不了多少请求,闲得无聊的时候只能和我聊天,这是没有办法的事情,因为整个系统只有我们两个: 没错, ...

  5. 获得32位UUID字符串和指定数目的UUID

    在common包中创建类文件UUIDUtils.java package sinosoft.bjredcross.common; import java.util.UUID; public class ...

  6. select2插件用法

    1.修改默认查询方法,使其可以根据value查询 this.element.select2({ allowClear: true, matcher: function (term, text, ele ...

  7. Javaweb拦截器

    http://blog.csdn.net/reggergdsg/article/details/52962774

  8. PHP基础(命名错误)错误导致的500

    记得去年七月份参与一个项目发生的一个低级错误 因为不小心在命名一个方法时使用了一list做为名称,因此在后面无明业火被点燃. 发现一个500,无论如何调整总是500,数据库,文件,url都正确,但就是 ...

  9. Ubuntu16.04 安装Tensorflow1.7过程记录二:安装CUDA及Tensorflow

    参考 How to install Tensorflow 1.7.0 using official pip package 其中的CUDNN应该改为7.05for CUDA9.0 后面安装的spyde ...

  10. C#的app.Config文件中设置,可以选择执行环境(左配置,有程序),app.Config中的appSettings首字母必须小写,符合源码要求