poj3660 cow contest
这题主要是传递闭包
题意: 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的更多相关文章
- POJ3660——Cow Contest(Floyd+传递闭包)
Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- POJ-3660.Cow Contest(有向图的传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17797 Accepted: 9893 De ...
- POJ3660:Cow Contest(Floyd传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16941 Accepted: 9447 题目链接 ...
- POJ3660 Cow Contest —— Floyd 传递闭包
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ3660 Cow Contest floyd传递闭包
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ3660 Cow Contest【最短路-floyd】
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
- POJ-3660 Cow Contest( 最短路 )
题目链接:http://poj.org/problem?id=3660 Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, ar ...
- poj3660 Cow Contest(Floyd-Warshall方法求有向图的传递闭包)
poj3660 题意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 分析: 在这呢先说一下关系闭包: 关系闭包有三种: 自反闭包(r), 对 ...
- 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 ...
- POJ-3660 Cow Contest Floyd传递闭包的应用
题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...
随机推荐
- vue-computed计算属性用法
siytem函数可以当做变量在html中展现,列:{{siytem}} v-for(item in siytem)遍历也可以. 这个函数是从获取到的数据中,得到值后再次提取里面的数据,通过下标 me ...
- swift 移除控制器中的已经存在的VC 注意
1.要用 || 2. 如果使用这个代码 只会移除一个VC
- 跨DB Server创建View
exec sp_configure 'show advanced options',1reconfigureexec sp_configure 'Ad Hoc Distributed Queries' ...
- stark组件开发之组合搜索基本显示
数据的获取,上一篇,已经有了!然后就是,如何进行展示的问题.到了展示这里,又有了新的问题, 因为从数据库,取得的数据. 分为 queryset 和 tuple 两种数据结构.tuple 中,只是字符串 ...
- 十四、new Comparator<T>实现多重排序结果
1.编写实现类 package com.abcd; public class Person{ private String name; private int age; private int sal ...
- linux下搭建Jenkins环境
前提:Tomcat.jdk已安装并配置成功,具体安装和配置可参考我的其他随笔,在此不再详述 1.官网下载Jenkins最新war包,jenkins.war 2.进入Tomcat安装目录,创建Jenki ...
- 1、背景介绍及移动云MAS平台 --短信平台
目的: 刚开发完成一套短信平台以及一个Web端短信发送系统,短信平台耗时两个周.短信发送系统耗时两个多月,开发使用的技术没什么高科技含量,在此主要是记录下很多情况的处理方案,希望能让大家提出改善方案和 ...
- 微信小程序实战[01]
接触微信小程序也有一段时间了,以天气预报练一下手. 主要实现了以下功能: (1) 首页图标式菜单,便于以后扩展功能 (2)首页顶部滚动消息 (3)页面右上角三点菜单转发功能,便于小程序的传播 (4)天 ...
- VUE 组件通信、传值
一.通过路由进行带参传值: 两个组件A和B,A组件通过query把orderId传递给B组件(触发事件可以是点击事件.钩子函数等) this.$router.push({path:'/componen ...
- @ReequestParam
@RequestParam:传递参数,即将请求参数区数据映射到功能处理方法的参数上 eg. public String queryUserName(@RequestParam String usern ...