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 ≤ AN; 1 ≤ BN; AB), 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
分析:有人说叫闭包传递。这题就是用一种类似于floyd的算法,
开始时,如果a胜b则由a到b连一条边。这样所有a能走到的点都是排名在a以后的。
所有能走到a的点都是排名在a以前的。用floyd,求出每个点能到达的点。
如果有一个点,排名在它之前的和排名在它之后的点之和为n-1,那么它的排名就是确定的。
#include<iostream>
using namespace std ;
int main()
{
int N,M,a,b;
cin>>N>>M;
int aa[110][110]={0};
while(M--)
{
cin>>a>>b;
aa[a][b]=1;
} for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
{
if(aa[j][i]&&aa[i][k])
aa[j][k]=1;
}
int ans=0;
for(int i=1;i<=N;i++)
{
int tmp=0;
for(int j=1;j<=N;j++)
tmp+=aa[i][j]+aa[j][i];
if(tmp==N-1)ans++; } cout<<ans<<endl;
return 0;
}

  

poj-3660-cows contest(不懂待定)的更多相关文章

  1. 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 ...

  2. POJ 3660 Cow Contest

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

  3. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  4. POJ 3660 Cow Contest 传递闭包+Floyd

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

  5. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

  6. poj 3660 Cow Contest(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

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

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

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

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

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

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7690   Accepted: 4288 Descr ...

  10. POJ 3660 Cow Contest (floyd求联通关系)

    Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...

随机推荐

  1. 微信开源的Android热补丁框架 Tinker

    前不久,微信开源了其Android热补丁框架Tinker,它的特别之处在于放在github.com/Tencent下面,是该账号下第一个正式的开源项目,可以看到腾讯对它的重视和认可. 早在6月份微信客 ...

  2. dojo之dojox/data/CsvStore初始化

    dojo之dojox/data/CsvStore初始化 1.var csvStore = new dojox.data.CsvStore({url:"student.csv"}); ...

  3. eclipse怎么恢复原状

    eclipse怎么恢复原状 今天,我在写JSP页面时,将eclipse缩小窗口,后来我准备恢复,但是窗口却变成下面的状态

  4. offline页面开发常用方法及页面控件验证

    offline页面开发常用方法及页面控件验证,对一些CheckBoxList操作进行封装,新人可以直接使用该代码. 1.返回上一页网址 /// <summary> /// Descript ...

  5. Linux显示按文件名降序文件

    Linux显示按文件名降序文件 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ls -lr 总用量 56 drwxr-xr-x 3 youhaidong yo ...

  6. ubuntu14.04 64位 安装eclipse

    ubuntu14.04 64位 安装eclipse 1 在官网上下载eclipse http://www.eclipse.org/downloads/下载eclipse-jee-luna-SR1-li ...

  7. freemarker写select组件(二十二)

    一,讲解一 1.宏定义 <#macro select id datas> <select id="${id}" name="${id}"> ...

  8. 手机端仿ios的银行下拉脚本五

    代码 <script> $('#bankName').click(function(){ var $this = $(this); new Picker({ "title&quo ...

  9. Fragment加载方式与数据通信

    一.加载方式 1. 静态加载 1.1 加载步骤 (1) 创建fragment:创建自定义Fragment类继承自Fragment类,同时将自定义Fragment类与Fragment视图绑定(将layo ...

  10. Python机器学习 (Python Machine Learning 中文版 PDF)

    Python机器学习介绍(Python Machine Learning 中文版) 机器学习,如今最令人振奋的计算机领域之一.看看那些大公司,Google.Facebook.Apple.Amazon早 ...