题目链接:

http://poj.org/problem?id=3660

题目大意:

给出n头牛,m个关系,关系为a的战力比b高。求最后可以确定排名的牛的数量

思路:

1.如果一头牛跟其他所有牛都确定了一个输赢关系,那么该牛的排名就得到了确定,所以用floyd跑一遍传递闭包。然后求得每个点的出度(赢了), 入度(输了)。若该点的度之和为 n - 1 ,即确定排名。

 #include<stdio.h>
#include<string.h>
#define mem(a, b) memset(a, b, sizeof(a))
const int MAXN = ; int n;
int map[MAXN][MAXN]; //表示i赢j
int in[MAXN], out[MAXN]; void floyd()
{
for(int k = ; k <= n; k ++)
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
if(map[i][k] && map[k][j])
map[i][j] = ;
} int main()
{
int m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
map[a][b] = ;
}
floyd();
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
if(map[i][j])
{
out[i] ++;
in[j] ++;
}
int ans = ;
for(int i = ; i <= n; i ++)
if(out[i] + in[i] == n - )
ans ++;
printf("%d\n", ans);
return ;
}

POJ 3660 Cow Contest【floyd】的更多相关文章

  1. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  2. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  3. POJ 3660 Cow Contest【Floyd 传递闭包】

    传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...

  4. POJ 3660 Cow Contest 传递闭包+Floyd

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

  5. POJ 3660 Cow Contest (floyd求联通关系)

    Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...

  6. POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16341   Accepted: 9146 Desc ...

  7. POJ 3660 Cow Contest (Floyd)

    http://poj.org/problem?id=3660 题目大意:n头牛两两比赛经过m场比赛后能判断名次的有几头可转 化为路径问题,用Floyd将能够到达的路径标记为1,如果一个点能 够到达剩余 ...

  8. (中等) POJ 3660 Cow Contest,Floyd。

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

  9. poj 3660 Cow Contest (bitset+floyd传递闭包)

    传送门 解题思路 考试题,想到传递闭包了,写了个O(n^3)的,T了7个点...后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32) #inc ...

随机推荐

  1. sql 存储过程例子和学习demo

    -------------------------------------------------------------------------- ------------------------- ...

  2. leetcode解题报告(10):Merge Two Sorted Lists

    描述 Merge two sorted linked lists and return it as a new list. > The new list should be made by sp ...

  3. 【线性代数】5-2:置换和余因子(Permutations and Cofactors)

    title: [线性代数]5-2:置换和余因子(Permutations and Cofactors) categories: Mathematic Linear Algebra keywords: ...

  4. sql注入笔记-mysql

    整理下sql相关知识,查漏补缺(长期更新) 1 常用语句及知识 information_schema包含了大量有用的信息,例如下图 mysql.user下有所有的用户信息,其中authenticati ...

  5. error:Cannot pull with rebase

    原文文链接:https://blog.csdn.net/u012385190/article/details/70670213git 执行git pull –rebase报错误如下: error: C ...

  6. computer5 environment

    luo@luo-All-Series:~/MyFile/Anaconda3$ luo@luo-All-Series:~/MyFile/Anaconda3$ luo@luo-All-Series:~/M ...

  7. mac 终端杀进程

    killall 进程名 killall chromedriver 查看进程名的·方法:

  8. python3 @classmethod 和 @staticmethod 的区别

    如果您将某个东西定义为classmethod,这可能是因为您打算从类而不是类实例中调用它. 定义类方法的几种方式: 常规方式                       : 需要self隐士传递当前类 ...

  9. Python字符串逐字符或逐词反转方法

    Python字符串逐字符或逐词反转方法 这篇文章主要介绍了Python字符串逐字符或逐词反转方法,本文对逐字符或逐词分别给出两种方法,需要的朋友可以参考下 目的 把字符串逐字符或逐词反转过来,这个蛮有 ...

  10. pyenv激活虚拟环境失败

    在使用 pyenv 版本管理工具时激活虚拟环境报错 $ pyenv virtualenvs  #列出当前虚拟环境 $ pyenv activate env-3.6.0 #激活虚拟环境 报错信息: Fa ...