Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8794   Accepted: 4948

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 Input

5 5
4 3
4 2
3 2
1 2
2 5

Sample Output

2

题意:给出N个奶牛,M个比赛结果,问最终有几个奶牛可以确定排名。
思路:将N个奶牛视作N个结点,若奶牛a战胜奶牛b,则结点a到结点b有一个有向路径,若奶牛c的排名可以确定,那么能到达结点c的结点个数与c能到达的结点个数之和为n-1
/*
Accepted 420K 32Ms */
#include"cstdio"
using namespace std;
const int MAXN=;
int mp[MAXN][MAXN];
int N,M;
int main()
{
while(scanf("%d%d",&N,&M)!=EOF)
{
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
if(i==j) mp[i][j]=;
else mp[i][j]=;
for(int i=;i<M;i++)
{
int u,v;
scanf("%d%d",&u,&v);
mp[u][v]=;
} for(int k=;k<=N;k++)
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
if(mp[i][k]==&&mp[k][j]==)
mp[i][j]=; int ans=; for(int i=;i<=N;i++)
{
int num=;
for(int j=;j<=N;j++)
if(mp[i][j]==) num++; for(int j=;j<=N;j++)
if(mp[j][i]==) num++; if(num-==N-) ans++;
} printf("%d\n",ans);
}
return ;
}

POJ3660(foyld闭包问题)的更多相关文章

  1. poj3660 Cow Contest(Floyd-Warshall方法求有向图的传递闭包)

    poj3660 题意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 分析: 在这呢先说一下关系闭包: 关系闭包有三种: 自反闭包(r), 对 ...

  2. 《Web 前端面试指南》1、JavaScript 闭包深入浅出

    闭包是什么? 闭包是内部函数可以访问外部函数的变量.它可以访问三个作用域:首先可以访问自己的作用域(也就是定义在大括号内的变量),它也能访问外部函数的变量,和它能访问全局变量. 内部函数不仅可以访问外 ...

  3. 干货分享:让你分分钟学会 JS 闭包

    闭包,是 Javascript 比较重要的一个概念,对于初学者来讲,闭包是一个特别抽象的概念,特别是ECMA规范给的定义,如果没有实战经验,很难从定义去理解它.因此,本文不会对闭包的概念进行大篇幅描述 ...

  4. 深入浅出JavaScript之闭包(Closure)

    闭包(closure)是掌握Javascript从人门到深入一个非常重要的门槛,它是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现.下面写下我的学习笔记~ 闭包-无处不 ...

  5. javascript之闭包理解以及应用场景

    半个月没写博文了,最近一直在弄小程序,感觉也没啥好写的. 之前读了js权威指南,也写了篇博文,但是实话实说当初看闭包确实还是一头雾水.现在时隔一个多月(当然这一段时间还是一直有在看闭包的相关知识)理解 ...

  6. js闭包 和 prototype

    function test(){ var p=200; function q(){ return p++; } return q; } var s = test(); alert(s()); aler ...

  7. js闭包for循环总是只执行最后一个值得解决方法

    <style> li{ list-style: none;width:40px;height: 40px;text-align:center;line-height: 40px;curso ...

  8. JavaScript学习笔记(二)——闭包、IIFE、apply、函数与对象

    一.闭包(Closure) 1.1.闭包相关的问题 请在页面中放10个div,每个div中放入字母a-j,当点击每一个div时显示索引号,如第1个div显示0,第10个显示9:方法:找到所有的div, ...

  9. 带你一分钟理解闭包--js面向对象编程

    上一篇<简单粗暴地理解js原型链--js面向对象编程>没想到能攒到这么多赞,实属意外.分享是个好事情,尤其是分享自己的学习感悟.所以网上关于原型链.闭包.作用域等文章多如牛毛,很多文章写得 ...

随机推荐

  1. Mysql 免密码登录,修改密码及忘记密码操作

    ----免密码登陆 方式一 my.cnf增加[client]标签 [client] user="root" password="你的密码" 单对定义不同的客户端 ...

  2. 必会必知git

    git必会必知   1 前言 git前身是BitKeeper,但是他不是开源软件,不符合当时开源趋势,于是就会有了开源的git,git开发只用了十天时间.目前git是公司开发必不可少的一个工具,用于多 ...

  3. Android模糊效果总结

    1. 软件模糊 用软件的方法.利用cpu计算,无sdk版本号要求. 效果图: 关键模糊代码 github链接 原文 链接 译文 链接 演示样例 代码 本文地址 :http://blog.csdn.ne ...

  4. ASP.NET动态网站制作(2)--css(1)

    前言:这节课主要讲关于css的相关内容. 重点:1.css(Cascading Style Sheet)叠层样式表,做网页的外观,是用来控制网页样式并允许将样式信息与网页内容分离的一种标记性语言. 2 ...

  5. python 基础 7.1 datetime 获得时间

    一 datatime 的使用   object         timedeta         tzinfo         time         data                dat ...

  6. mongo数据库中一条记录中某个属性是数组情形时 数据结构的定义

    package entity; import java.util.Date; import com.mongodb.BasicDBList;import com.mongodb.DBObject; p ...

  7. CSS定位细节

    记住此三句话,很好的解决了关于浮动方面的问题: 1.浮动的元素对于没有设置浮动的元素来说是不存在的,浮动的元素将会覆盖没有浮动的元素 如图:先让d1浮动在left ,d2位置不浮动,d1覆盖了d2之上 ...

  8. 关于maven的profile

    1 什么是profile profile本质上就是不同的环境对应不同的配置. 这样的好处是,在命令行中指定具体的profile的时候,会有自己独特的参数或者独特的配置来为不同的环境生成不同的目标代码. ...

  9. git config --system --unset credential.helper 重新输入账号密码

    检查本地配置$ git config --local -lcore.repositoryformatversion=0core.filemode=falsecore.bare=falsecore.lo ...

  10. mysql系列之1.mysql基础

    非关系型(NOSQL)数据库 键值存储数据库: memcached  /  redis  /  memcachedb  /  Berkeley db 列存储数据库: Cassandra  /  Hba ...