POJ 3660 Cow Contest 任意两点之间的关系 Floyd
题意:牛之间有绝对的强弱,给出一些胜负关系,问有多少头牛可以确定其绝对排名。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1); int g[105][105],n,m; void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(g[j][k]&&g[k][i])
g[j][i]=1;
} int main()
{
while(~scanf("%d %d",&n,&m))
{
MM(g,0);
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d %d",&x,&y);
g[y][x]=1;
}
floyd();
int ans=0;
for(int i=1;i<=n;i++)
{
int temp=0;
for(int j=1;j<=n;j++)
temp+=g[i][j]+g[j][i];
if(temp==n-1) ans++;
}
printf("%d\n",ans);
}
return 0;
}
分析:
1.一头牛的排名能确定的话,那么肯定他跟其余的n-1头牛的胜负关系都已经(直接或间接)确定好了,因此,只需判断这头牛是否与其他牛的胜负关系确定了没有。
2.A输给了B,B输给了C,那么A肯定会输给C,要确定任意两头牛之间的胜负关系,可以使用Floyd,注意
Floyd不仅可以确定任意两点之间的最短路径,还可以确定出他们之间的相对关系,同样是通过最外面一层循环的更新思想实现。
POJ 3660 Cow Contest 任意两点之间的关系 Floyd的更多相关文章
- POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )
题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...
- 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求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
- 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,Floyd。
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
随机推荐
- ElasticSearch 7.3.0 查询、修改、删除 文档操作
PUT chuyuan/_doc/ { "name":"xiaolin", , "sex":"F", "lov ...
- python 并发编程 非阻塞IO模型
非阻塞IO(non-blocking IO) Linux下,可以通过设置socket使其变为non-blocking.当对一个non-blocking socket执行读操作时,流程是这个样子: 从图 ...
- 洛谷 P2801 教主的魔法 题解
题面 刚看到这道题的时候用了个树状数组优化前缀和差分的常数优化竟然AC了?(这数据也太水了吧~) 本人做的第一道分块题,调试了好久好久,最后竟然没想到二分上还会出错!(一定要注意)仅此纪念: #inc ...
- window下的php命令行输出汉字乱码处理
1. 在php的代码中加入 header("content-type:text/html;charset=gbk"); 2. 设置命令行的字体 在命令行上右击属性 字体 选择如下字 ...
- redis 哈希 数据类型
哈希 hset 设置哈希表字段 hset 8000 ename tom hset 8000 job salesman hget 8000 ename "tom" hget ...
- --解决Lock wait timeout exceeded; try restarting transaction
--解决Lock wait timeout exceeded; try restarting transaction select * from information_schema.innodb_t ...
- qt QAbstractItemModel一些方法介绍
一. virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::Edit ...
- kibana报[FORBIDDEN/12/index read-only / allow delete (api)]错误
一.错误描述 1.在kibana,dev中pose数据,报[FORBIDDEN/12/index read-only / allow delete (api)]错误. 尝试过网上的说的方法一:在kib ...
- 将div的内容生成清晰的PDF、高清PDF
//需要引入html2canvas.js.jquery.js文件 html: <button type="button" class="btn btn-primar ...
- 作为测试人员,不能不懂的adb命令和操作
刚从web转到app测试,很多知识需要补充,记录一下 1.概念 其实我们口中所讲的adb是个泛指,这其中有两个工具——Fastboot和ADB fastboot 快速启动,usb链接数据线的一 ...