POJ 3660 Cow Contest 弗洛伊德
题意难懂是POJ的标配,这都TM赖本泽马。
题意:有N头牛进行了M场比赛,比赛双方是A - B 且总是A赢(前面的那个数赢),如果说A赢B,B赢C 则可以确定A赢C。问最终多少头牛的排名可以确定。
思路:用弗洛伊德判读每两点之间是否有输赢关系(INF表示没关系),如果某个点与所有点都有输赢关系,则这个点的排名可以确定。
#include<stdio.h>
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<queue>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<cmath> #define INF 0x3f3f3f3f
#define MAX 1005 using namespace std; int Map[MAX][MAX],n,vis[MAX],dist[MAX],m; int ford()
{
int i,j,k,sum,ans=0; for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(Map[i][j] > Map[i][k]+Map[k][j])
Map[i][j] = Map[i][k]+Map[k][j];
}
}
} for(i=1;i<=n;i++)
{
sum=0;
for(j=1;j<=n;j++)
{
if((Map[i][j]!=INF || Map[j][i]!=INF) && i!=j)
sum++;
} if(sum==n-1)
ans++;
} return ans;
} int main()
{
int i,j,a,b; while(scanf("%d%d",&n,&m)!=EOF)
{
memset(Map,INF,sizeof(Map)); for(i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
Map[a][b]=1;
} int ans=ford(); printf("%d\n",ans);
}
}
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 ...
随机推荐
- android 实践项目
电子词典 http://files.cnblogs.com/blogLYF/lyf_danci.apk
- nginx(ubuntu)设置别名访问目录
1 2 3 4 5 6 7 8 9 10 11 12 13 location /phpmyadmin/ { alias /data/phpmyadmin/; index index.html in ...
- Python2中while 1比while True更快
1) bool类是从int类继承而来的 2) True/False 在python2中不是关键字,但是在python3是(True,False,None) PS > python2 Enthou ...
- python实现邮件发送
实例补充: #**************************利用STMP自动发送邮件******************************import smtplibsmtp = smtp ...
- 50个很棒的Python模块
50个很棒的Python模块 我很喜欢Python,Python具有强大的扩展能力,我列出了50个很棒的Python模块,包含几乎所有的需要:比如Databases,GUIs,Images, Soun ...
- Chapter 1 First Sight——31
I took notes carefully anyway, always looking down. 不论怎么样我都仔细的记着笔记,一直低着头. I couldn't stop myself fro ...
- 第一次使用unity3d
今天暂且做个记录,因为第一使用了unity3d,进行了很长时间的安装和调试,进行了简单的使用,能简单的在页面上面建立了一个方块和一个球. 简单了解了unity中的一些基本概念.总结一下,一个物体可以有 ...
- <context:annotation-config/>
转自:Spring <context:annotation-config/> 解说 在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-c ...
- InjectAPC全部项目(Win32和Win64位)
// InjectAPC.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> #inclu ...
- iOS中静态库-.a文件生成和使用
最近在使用使用一个网上的Demo的时候. 出现另一令人烦恼的问题 . 就是它里面有嵌套的工程. 如下图所示. 工程里面还嵌套有一个工程. 真的是让人煞费苦心 …其实这个问题看起来并不是很难, 如果是一 ...