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 5 5 Sample Output 2 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时可以知道排名,即为 ...
随机推荐
- 20164310Exp6 信息搜索和漏洞扫描
实践内容 (1)各种搜索技巧的应用 (2)DNS IP注册信息的查询 (3)基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务的查点(以自己主机为目标) (4)漏洞扫描:会扫,会看报告, ...
- 通过 Composer 安装 Laravel 安装器
composer global require "laravel/installer" linux下确保 $HOME/.composer/vendor/bin 在系统路径中(Mac ...
- Windows 7无声音的解决方案
在使用Windows7的过程中,可能会遇到系统没有声音的问题.导致此问题的原因有以下几点: (1)电脑没有配置声音输出设备: (2)未安装声卡驱动: (3)声音输出设备硬件发生故障: (4)扬声器被禁 ...
- docker容器的常用操作
创建容器 [root@mydocker ~]# docker create --name test_create -ti ubuntu 1d13990eea0d3f282a0f7d5589f40e49 ...
- Oracle中文排序问题
默认感觉中文是按拼音排序,如果没实现效果,请加上其它排序,例如日期 表名为 dept ,其中name字段是中文,下面分别实现按照单位名称的笔划.部首和拼音排序.1: //按照笔划排序2: select ...
- vue 组件自定义v-model
参考资料:vue官网在vue 中使用v-model双向绑定 <input v-model="something"> 其实是语法糖 <input :value=&q ...
- C# 反射获取属性值、名称、类型以及集合的属性值、类型名称
实体类 class Product { public string Id { get; set; } public string Name { get; set; } public List<P ...
- Spring Boot+Spring Security:获取用户信息和session并发控制
说明 (1)JDK版本:1.8(2)Spring Boot 2.0.6(3)Spring Security 5.0.9(4)Spring Data JPA 2.0.11.RELEASE(5)hiber ...
- 从RDS中获取binlog
由于使用RDS,但是没有开启日志,所以需要分析时,发现根本没有日志可以下载. 但是RDS中是存在binlog的,那么直接在线获取 首先在一台能够连接上RDS的数据中安装对应版本的mysql客户端. 到 ...
- leetcode每日刷题计划-简单篇day5
刷题成习惯以后感觉挺好的 Num 27 移除元素 Remove Element 跟那个排序去掉相同的一样,len标记然后新的不重复的直接放到len class Solution { public: i ...