这题主要是传递闭包

题意: 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. 【java】多个对象的序列化和反序列化

    当我们需要序列化多个对象的时候,可以采用集合把多个对象放到集合中,然后序列化整个集合. 而我们要反序列化的时候,就使用集合接收反序列化后的对象 如: List<Student> stude ...

  2. js 一键复制

    function copyURL(id){ var siteId=$("#siteId").val() var oInput = document.createElement('i ...

  3. jumpserver笔记

    一.安装docker使用官方脚本自动安装 curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 二.拉取jumperse ...

  4. django filter or 多条件查询

    功能:django中实现多条件查询 或关系: from django.db.models import Q return qs.filter(Q(notice_to_group__contains=' ...

  5. Android 8.0+ 通知不显示的适配

    最近在 写项目的时候  发现 通知并不会显示的问题,查看资料发现 从Android 8.0开始通知必须加上ChannelId Android O 引入了 通知渠道(Notification Chann ...

  6. Checked Uncheckd异常

    Checked : 你可以在写代码的时候就throw 或者try catch 的 Unchecked :  Error   + RuntimeException .提前无法预测的 http://www ...

  7. linux服务配置

    1,开机初始化的配置 iptables -F 清空防火墙 /etc/init.d/iptables stop  #关闭iptables setenforce 0  #暂停selinux #编译安装py ...

  8. VBA 插入图片到指定单元格并保存图片为图片文件

    'Upload File to the specific folder Sub UploadImages(s$, c$) 's$ Buttom number 'c$ Specify a locatio ...

  9. PHP整理--PHP语句流程

    PHP跟JS一样是从上往下的执行语句:同样的PHP也有if语句.循环.数组和函数. 一.条件语句   if..else...    swich  (1)多条if语句 $name=30; if($nam ...

  10. 如何修改PCB后更新到原理图(以AD为例)

    实际绘图过程中会有多种情况发生,例如根据以前的项目做修改应用于新的项目.只有PCB没有原理图....... 如何通过修改PCB后更新到原理图(主要在PCB中增加元器件以及添加网络标号进行连线后更新到原 ...