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 ≤ NA ≠ 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
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined

Sample

Sample Input

Sample Output

题意:

  有n头牛比赛,m种比赛结果,最后问你一共有多少头牛的排名被确定了,其中如果a战胜b,b战胜c,则也可以说a战胜c,即可以传递胜负。求能确定排名的牛的数目。

思路:

  如果一头牛被x头牛打败,打败y头牛,且x+y=n-1,则我们容易知道这头牛的排名就被确定了,所以我们只要将任何两头牛的胜负关系确定了,在遍历所有牛判断一下是否满足x+y=n-1,将满足这个条件的牛数目加起来就是所求解。如果出度+入度=顶点数-1,则能够确定其编号。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int map[][];
int n,m;
void floyd()
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(map[i][k]==&&map[k][j]==)//关系传递
map[i][j]=;
}
int main()
{
cin>>n>>m;
memset(map,,sizeof(map));
for(int i=;i<m;i++)
{
int a,b;
cin>>a>>b;
map[a][b]=;//单向边
}
floyd();
int ans=;
for(int i=;i<=n;i++)
{
int sum=;
for(int j=;j<=n;j++)
{
if((map[i][j]==||map[j][i]==)&&i!=j)
sum++;//计算出度和入度
}
if(sum==n-)
ans++;
}
cout<<ans;
}

POJ3660 Cow Contest floyd传递闭包的更多相关文章

  1. POJ3660——Cow Contest(Floyd+传递闭包)

    Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...

  2. POJ3660 Cow Contest —— Floyd 传递闭包

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  3. POJ-3660 Cow Contest Floyd传递闭包的应用

    题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...

  4. POJ3660:Cow Contest(Floyd传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接 ...

  5. POJ-3660.Cow Contest(有向图的传递闭包)

      Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 De ...

  6. ACM: POJ 3660 Cow Contest - Floyd算法

    链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Descri ...

  7. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  8. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  9. poj 3660 Cow Contest (传递闭包)

    /* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...

随机推荐

  1. Qt开发陷阱一QSTACKWIDGET

    原始日期:2015-10-14 00:55 1.使用QStackWidget控件的setCurrentIndex方法时,要注意参数0对应着ui上StackWidget的page1,而不是page0,没 ...

  2. 可能是最详细的 Hexo + GitHub Pages 搭建博客的教程

    前言:博主目前大三,Web 前端爱好者.写博客的好处,不是为了写而写,而是一个记录思想的过程.不要考虑它能带给你什么,而是你自己从中收获了什么. 最近刚好有空,于是就参照网上的各种教程,搭建了一个博客 ...

  3. Redis客户端管理工具,状态监控工具

    TreeNMS是一款Redis web客户端管理工具,采用JAVA开发,实现基于web方式对Redis数据库进行管理.监控.数据维护. 功能包括:数据库的状态监控,库表的展示,key,value的展示 ...

  4. Linux下SVN+多个Tomcat自动部署

    项目中都是jsp开发,所以用到Tomcat. 在我文章中也写过多个Tomcat 的部署,具体可以参考:http://www.cnblogs.com/magmell/p/7045193.html SVN ...

  5. 拉勾网招聘数据分析(Echarts, SQL, java)

    这次的数据分析与决策课程,我做的是通过爬取拉勾网上的招聘信息,并用爬取到的数据整体分析互联网行业数据,项目做得差不多了,先总结下吧,后边有时间了再完善. 主要工具:  Echarts, SQL, ja ...

  6. 序列、视图、索引(面试看这个就GO了)

    oracle内置对象 序列.视图.索引 序列 create sequence aaa start with 1; 使用 视图 创建好之后 然后直接用 就OK了 有了视图可以代替子查询,使得sql简洁 ...

  7. VMvare虚拟机的安装及新建虚拟机.

    一.VMvare虚拟机的安装 1.首先双击--你下载的安装包,这里我分享百度云盘,供大家下载:http://pan.baidu.com/s/1jImQSZG 2.VMware Workstation ...

  8. java的多线程初体验

    这里以车站售票作为模拟场景,多个票务人员同时出售某一列高铁(G250?)的车票,售票的基本保证有2点: 1.不能售出多于预定限额的车票. 2.不能售出具有相同座位的车票. 初学java,有不当的地方各 ...

  9. View学习(二)-View的测量(measure)过程

    在上一篇文章中,我们介绍了DecorView与MeasureSpec, 下面的文章就开始讨论View的三大流程. View的三大流程都是通过ViewRoot来完成的.ViewRoot对应于ViewRo ...

  10. Chrome浏览器扩展开发系列之十三:消息传递Message

    由于content scripts运行在Web页面的上下文中,属于Web页面的组成部分,而不是Google Chrome扩展程序.但是content scripts又往往需要与Google Chrom ...