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时可以知道排名,即为 ...
随机推荐
- 【转载】许纪霖教授在上海财经大学演讲——漫谈“大学生的四个Learn”
这几年,越来越多的大学毕业生抱怨找不到合意的工作.很多单位又感叹,找一个称职的大学生真难.这就形成一个非常大的反差和矛盾.那么,社会究竟需要怎样的大学生?我们的大学到底应该培养怎样的大学生?我们作为大 ...
- Mock Server
下载地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/ 此处使用standalone的方式,不使用api用法 启动方 ...
- 跨年呈献:HP-Socket for Linux 1.0 震撼发布
三年,三年,又三年,终于,终于,终于不用再等啦!就在今天,HP-Socket for Linux v1.0 震撼发布!还是一样的接口,一样的高效,一样的简便,一样的味道. HP-Socket ...
- Vue 表格里的下拉列表
下拉列表column-select.vue组件内容: <template> <div class="column-select-wrapper"> < ...
- js关闭浏览器
不存在的 告诉策划:不好意思,这个需求实现不了. 旧版本浏览器有些支持window.close()方法,目前主流浏览器都不支持,就算让你 ...
- Postman A请求的返回值作为B请求的入参( 拢共分三步)
- Timer与TimerTask
Timer和TimerTask Timer是一种定时器工具,用来在一个后台线程计划执行指定任务.它可以计划执行一个任务一次或反复多次.TimerTask一个抽象类,它的子类代表一个可以被Timer计划 ...
- 关于python的多行注释,启动新浏览器,循环语句乘法口诀
1,提问:如何将python写的多行代码改写成注释,进行写下一段代码?这样可以在多个脚本中写东西? 回答:百度了一下,还真有 选中所要注释的代码 CTRL + / 然后所选的代码前面都会出现#,编程 ...
- Python第5天
今日学习的主要内容: 数据类型和变量的总结:(可变:列表,字典)(不可变:字符串,数字,元组) 引出集合概念:不同元素,无序,不可变类型 set方法—>集合 add添加:clear清空:pop删 ...
- tomcat Server启动带profile文件
一般mvn如果配置有环境,直接在tomcat server中无法直接启动,需要在vm或者tomcat启动中添加profile启动. pom.xml中添加: 在<profile>中添加默认p ...