原题链接:http://poj.org/problem?id=3660

Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8395   Accepted: 4734

Description

N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.

The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ NA ≠ B), then cow A will always beat cow B.

Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.

Input

* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined
 

Sample Input

5 5
4 3
4 2
3 2
1 2
2 5

Sample Output

2

Source

题意

给你若干牛之间的优劣关系,问你有多少头牛能够被确定排名。

题解

如果有x头牛比当前牛弱,有y头牛比当前牛强,并且x+y=n-1,那么这头牛的排名就被唯一确定了。转化为图论问题,我们若牛a比牛b强,则连接a,b(单向)。运用floyd的思想,令dp[i][j]表示从i能够走到j,即牛i和牛j之间存在强弱关系,那么转移就是dp[i][j]=dp[i][j] | (dp[i][k] & dp[k][j]),跑一发floyd,再统计每个点的度即可。

代码

#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define MAX_N 111
using namespace std; bool d[MAX_N][MAX_N];
int n,m; void floyd() {
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
d[i][j] = d[i][j] | (d[i][k] & d[k][j]);
} int de[MAX_N]; int main() {
cin.sync_with_stdio(false);
cin >> n >> m;
for (int i = ; i < m; i++) {
int u, v;
cin >> u >> v;
d[u][v] = ;
}
floyd();
int ans = ;
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
de[i] += d[i][j], de[j] += d[i][j];
for (int i = ; i <= n; i++)if (de[i] == n - )ans++;
cout << ans << endl;
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(Floyd求传递闭包(可达矩阵))

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

  3. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

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

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

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

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

  6. POJ 3660 Cow Contest. (传递闭包)【Floyd】

    <题目链接> 题目大意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 解题分析: 首先,做这道题要明确,什么叫确定牛的排名.假设 ...

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

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

  8. POJ 3660 Cow Contest(传递闭包)

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  9. POJ 3660 Cow Contest【floyd】

    题目链接: http://poj.org/problem?id=3660 题目大意: 给出n头牛,m个关系,关系为a的战力比b高.求最后可以确定排名的牛的数量 思路: 1.如果一头牛跟其他所有牛都确定 ...

随机推荐

  1. 使用selenium和phantomJS浏览器登陆豆瓣的小演示

    # 使用selenium和phantomJS浏览器登陆豆瓣的小演示 # 导入库 from selenium import webdriver # 实例化一个浏览器对象 web = webdriver. ...

  2. STM32CUBEMX入门学习笔记3:HAL库以及STM32CUBE相关资料

    微雪课堂:http://www.waveshare.net/study/article-629-1.html 之前的正点原子的例程资料 硬石科技stm32cube: 链接:https://pan.ba ...

  3. socketserver的使用

    socketserver底层也是使用线程实现的并发,直接上代码 # server import socketserver ''' socketserver使用模式: 1 功能类 class Myser ...

  4. centos7 安装显卡驱动方法

    方法一: 首先需要添加一个第三方的源ELRepo.这个源支持RED HAT系的Linux系统,主要是提供一些硬件的驱动程序.这个源的主页如下: http://elrepo.org/tiki/tiki- ...

  5. Power Calculus UVA - 1374 迭代加深搜索

    迭代加深搜索经典题目,好久不做迭代加深搜索题目,拿来复习了,我们直接对当前深度进行搜索,注意剪枝,还有数组要适当开大,因为2^maxd可能很大 题目:题目链接 AC代码: #include <i ...

  6. sql获取指定表所有列名及注释

    SELECT b.name as 字段名 ,Type_name(b.xusertype) as 字段类型, Isnull(c.VALUE,'') as 字段说明FROM sysobjects a jo ...

  7. [转]mysql Access denied for user 'root'@'localhost' 问题的解决方法

    解决方案如下: # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &a ...

  8. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  9. list 类

    题外:len = sizeof(a)/sizeof(a[0]); 求出数组长度 1.list是一种以双向链表方式实现的一种顺序容器.list容器中,存放元素的存储单元可以是连续的也可以是不连续的. 2 ...

  10. malloc&&free的系统运行机制及其源代码的理解

    一.malloc()和free()的基本概念以及基本用法: 1.函数原型及说明: void *malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针 ...