Floyd_Warshall POJ 3660 Cow Contest
题意: m组关系,A能打败B,问最后有几头牛的排名能确定
分析:如果排名确定,那么能打败它的到它一定通,它到能打败的一定能通,也就是和为n-1.用Floyd的传递闭包
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int N = 1e2 + 5;
bool d[N][N];
int in[N];
int n, m; void Floyd_Warshall(void) {
for (int k=1; k<=n; ++k) {
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) {
d[i][j] = (d[i][j] || (d[i][k] && d[k][j]));
}
}
}
} int main(void) {
while (scanf ("%d%d", &n, &m) == 2) {
memset (d, false, sizeof (d));
memset (in, 0, sizeof (in));
for (int u, v, i=1; i<=m; ++i) {
scanf ("%d%d", &u, &v);
d[u][v] = true;
in[v]++;
}
Floyd_Warshall ();
int ans = 0;
for (int i=1; i<=n; ++i) {
int c1 = 0, c2 = 0;
for (int j=1; j<=n; ++j) {
if (i == j) continue;
if (d[i][j]) c1++;
if (d[j][i]) c2++;
}
if (c1 + c2 == n - 1) ans++;
}
printf ("%d\n", ans);
} return 0;
}
Floyd_Warshall POJ 3660 Cow Contest的更多相关文章
- 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
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 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——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 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 ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
随机推荐
- ArtDialog文档
http://www.planeart.cn/demo/artDialog/_doc/API.html#API
- iOS 多线程及其他补充
NSOperation NSOperation是个抽象类,并不具备封装操作的能力,必须使用它的子类 NSInvocationOperation 如果直接执行NSInvocationOperatio ...
- 编译QtAV工程库
去https://github.com/wang-bin/QtAV下载源代码 去https://sourceforge.net/projects/qtav/files/depends/QtAV-dep ...
- Collection 集合类
ArrayList: 基于动态数组的List 它有两个重要的变量,size为存储的数据的个数.elementData 数组则是arraylist 的基础,因为他的内部就是通过这个数组来存储数据的. p ...
- Ubuntu自定义服务
1.准备脚本 准备好一个bash服务脚本,包括start|stop|restart等参数,将脚本文件命名为“服务名”,拷贝到/etc/init.d/目录下. 2.添加服务sudo update-rc. ...
- MVC – 15.路由机制
15.1.路由检测插件 - RouteDebug 15.2.路由约束 15.3.命名路由 15.4.验证码 15.5.ASP.NET MVC 与 三层架构 15.6.Area区域 15.6.1.尝试将 ...
- 阿里云 SWAP
https://yq.aliyun.com/articles/52098 https://www.kejianet.cn/aliyun-swap/
- 排队打饭 sdut 2443【最简单的贪心法应用举例】
排队打饭 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- 使用html5 canvas绘制图片
注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...