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 ...
随机推荐
- 内核中用于数据接收的结构体struct msghdr(转)
内核中用于数据接收的结构体struct msghdr(转) 我们从一个实际的数据包发送的例子入手,来看看其发送的具体流程,以及过程中涉及到的相关数据结构.在我们的虚拟机上发送icmp回显请求包,pin ...
- iOS - 直播相关文章
直播相关文章 直播RTMP可用于测试的服务器地址 FFmpeg avdumpformat输出的tbn.tbc.tbr.PAR.DAR的含义 FFmpeg 3.0 计算视频时长 HLS Streamin ...
- web storm
常用插件: code glance 代码预览功能,用过的都知道有多爽...
- js函数的几个特殊点
在ECMAScript中,Function(函数)类型实际上是对象.每个函数都是Function类型的实例,而且都与其他引用类型一样具有属性和方法.由于函数是对象,因此函数名实际上也是一个指向函数对象 ...
- MyEclipse生成WAR包并在Tomcat下部署发布(转发)
从来没有想过web项目还能打包的,但是有要求,就不得不去实现,在网上找了一下,发现挺简单的. 首先是使用MyEclipse将web项目打包,如下图所示. 右键选中项目,选择export. 然后选择J2 ...
- Linux下第一次使用MySQL数据库,设置密码
在终端下输入:/etc/rc.d/init.d/mysqld status 查看MySQL状态,看看是否运行. 没有运行的话就输入:/etc/rc.d/init.d/mysqld start 这时,就 ...
- java 缩略图
http://www.cnblogs.com/digdeep/p/4829471.html http://www.jb51.net/article/57648.htm http://blog.csdn ...
- @ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4 "/" $NF}'中"[ :]+" 是什么意思?@
http://blog.csdn.net/zhuying_linux/article/details/6822987
- weblogic监控
http://wenku.baidu.com/link?url=tQPQ-dgm7NOkEGj_vemwtsPd6TJ6W3x6_0UBLgw61N982SwPlz-QFxqncsmPGqHwJAEF ...
- probe函数何时调用的
转自:http://blog.csdn.net/xiafeng1113/article/details/8030248 Linux中 probe函数何时调用的 所以的驱动教程上都说:只有设备和驱动的名 ...