POJ-3660.Cow Contest(有向图的传递闭包)
Cow Contest
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 ≤ N; A ≠ 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 Output * Line 1: A single integer representing the number of cows whose ranks can be determined Sample Input
Sample Output
Source |
本题思路:将题目给出的已知边都存入图中,利用传递性求出可能存在的每条边,对于一个学生,用i -> j表示 i 比 j 强,那么对于所有学生,他的排名被确定的条件就是确定他与其它所有同学的排名情况,即Bigger[ i ] + Smaller[ i ] == n - 1。
参考代码:(不建议看,按照上面的思路实现一波就行了)
- #include <cstdio>
- #include <cstring>
- #include <queue>
- using namespace std;
- const int maxn = + , INF = 0x3f3f3f3f;
- int n, m, a, b;
- bool G[maxn][maxn];
- int Floyd_Warshall() {
- int num = ;
- for(int k = ; k <= n; k ++) {
- for(int i = ; i <= n; i ++) {
- for(int j = ; j <= n; j ++) {
- G[i][j] = G[i][j] || (G[i][k] && G[k][j]);
- }
- }
- }
- for(int i = ; i <= n; i ++) {
- int temp = ;
- for(int j = ; j <= n; j ++)
- if(G[i][j] || G[j][i]) temp ++;
- if(temp == n - ) num ++;
- }
- return num;
- }
- int main () {
- scanf("%d %d", &n, &m);
- int x, y;
- for(int i = ; i < m; i ++) {
- scanf("%d %d", &x, &y);
- G[x][y] = true;
- }
- int ans = Floyd_Warshall();
- printf("%d\n", ans);
- return ;
- }
POJ-3660.Cow Contest(有向图的传递闭包)的更多相关文章
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest【Floyd 传递闭包】
传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...
- poj 3660 Cow Contest (bitset+floyd传递闭包)
传送门 解题思路 考试题,想到传递闭包了,写了个O(n^3)的,T了7个点...后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32) #inc ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
随机推荐
- es6入门总结
let和const命令 let命令 循环体的let变量只对花括号作用域可见,花括号外不可见 循环体的语句部分是一个父作用域,而循环体内部是一个单独的子作用域 let声明的变量不存在变量提升,未声明的使 ...
- send_keys results in Expected 【object Undefined】undefined to be a string解决方法:更新selenium+geckodriver+firefox
很久之前在win10上配置的测试环境: python 3.6.1+ selenium 3.3.3+ geckodriver 0.15.0以前run case是正常的,今天去run 同样的case时发现 ...
- numpy学习笔记(四)
(1)NumPy - 矩阵库 NumPy 包包含一个 Matrix库numpy.matlib.此模块的函数返回矩阵而不是返回ndarray对象. matlib.empty()返回一个新矩阵,而不初始化 ...
- 高性能 TCP & HTTP 通信框架 HP-Socket v4.3.1
HP-Socket 是一套通用的高性能 TCP/UDP/HTTP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP/HTTP 通信系统,提供 C/ ...
- vector用法
转:http://www.cnblogs.com/wang7/archive/2012/04/27/2474138.html 在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结. ...
- 4-linux、hdfs命令
定义: linux:Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的 操作系统.它能运行主要的UNIX工具软件.应用程序和 ...
- Centos7.3 编译安装GDAL以及Python的GDAL包
参考: https://cryolite.iteye.com/blog/176382 https://blog.csdn.net/a13326021319/article/details/782505 ...
- django之注册登录
清理session数据,自此django的认证登陆登出功能完成,但是此处有个问题,就是当用户在手动关闭浏览器的时候,session数据不会自动失效,数据库的session数据也不会自动删除,所以需要在 ...
- leetcode969
class Solution(object): def pancakeSort(self, A: 'List[int]') -> 'List[int]': n = len(A) result = ...
- drf框架之 路飞学城(第二天)
1.第二天的项目是用户购物的数据存入到购物车中,这样保存的数据是存放在redis中 1. 首先先配置redis的数据库链接: #注意, 数据从redis中获取到的内容,最原始的是二进制形式的数据,想要 ...