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头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...
随机推荐
- mysql判断表里面一个逗号分隔的字符串是否包含单个字符串、查询结果用逗号分隔
1.mysql判断表里面一个逗号分隔的字符串是否包含单个字符串 : FIND_IN_SET select * from tablename where FIND_IN_SET(传的参数,匹配字段) 例 ...
- Apache Flink 数据流编程模型
抽象等级(Levels of Abstraction) Flink提供不同级别的抽象来开发流/批处理应用程序. Statefule Stream Processing: 是最低级别(底层)的抽象,只提 ...
- Java反转二叉树
// 二叉树节点定义 public class BinaryTreefanzhuan { class TreeNode{ int value; TreeNode left; TreeNode righ ...
- Vue项目碰到"‘webpack-dev-server’不是内部或外部命令,也不是可运行的程序或批处理文件"报错
解决办法: 最后将项目里的“node_modules”文件夹删除,然后在cmd中cd到项目目录,依次运行命令:npm install和npm run build,最后运行npm run dev后项目成 ...
- Android 菊花加载工具类
先看看实现效果图 1.首先自定义一个类继承系统ProgressDialog /** * Created by hanbao0928 on 2018/11/1. */ public class Dial ...
- java打包发布程序.jar(Eclipse)
1.程序运行无错误后,右击项目名称,选择Export 2.next后,选择启动时的运行项目,选择压缩包的存储路径 3.finishi即可. 4.运行 cmd存储路径下>java -jar XXX ...
- spring 装配机制
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- 5个数组Array方法: indexOf、filter、forEach、map、reduce使用实例
ES5中,一共有9个Array方法 Array.prototype.indexOf Array.prototype.lastIndexOf Array.prototype.every Array.pr ...
- (转)Oracle定时执行计划任务
Oracle定时执行计划任务 在日常工作中,往往有些事情是需要经常重复地做的,例如每天更新业务报表.每天从数据库中提取符合条件的数据.每天将客户关系管理系统中的数据分配给员工做数据库营销……因此我们就 ...
- Jython 安装使用
Jython 官网:https://jython.org/ 下载 下载页面:https://jython.org/downloads.html jython-installer-${version}. ...