Cow Contest

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述

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.

输入
* 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



There are multi test cases.The input is terminated by two zeros.The number of test cases is no more than 20.
输出
For every case:

* Line 1: A single integer representing the number of cows whose ranks can be determined
样例输入
5 5
4 3
4 2
3 2
1 2
2 5
0 0
样例输出
2
////能打败的个数加上被打败的个数恰好等于n-1,则能确定,
////否则无法确定,抽象为简单的floyd传递闭包算法,
////在加上每个顶点的出度与入度 (出度+入度=顶点数-1,则能够确定其编号)。
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=102; int n,m;
int tu[maxn][maxn];
int main()
{
int i,j,k,x,y,ans;
while(~scanf("%d %d",&n,&m),n+m)
{
memset(tu,0,sizeof(tu));
while(m--)
{
scanf("%d %d",&x,&y);
tu[x][y]=1;
}
for(k=1; k<=n; k++)
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
if(tu[i][k]&&tu[k][j])
tu[i][j]=1;
int ans=0;
for(i=1; i<=n; i++)
{
int cont=n-1;
for(j=1; j<=n; j++)
if(tu[i][j]||tu[j][i])
cont--;
if(!cont)
ans++;
}
printf("%d\n",ans);
}
return 0;
}

nyoj 211&&poj 3660的更多相关文章

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

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

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

  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 传递闭包floyed算法

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

  5. POJ 3660 Cow Contest

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

  6. POJ 3660 Cow Contest (Floyd)

    http://poj.org/problem?id=3660 题目大意:n头牛两两比赛经过m场比赛后能判断名次的有几头可转 化为路径问题,用Floyd将能够到达的路径标记为1,如果一个点能 够到达剩余 ...

  7. POJ 3660 Cow Contest (Floyd)

    题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...

  8. (poj 3660) Cow Contest (floyd算法+传递闭包)

    题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...

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

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

随机推荐

  1. 拖放API中的drag和drop实战

    原文地址:→传送门 写在前面 在HTML5之前,实现拖放功能需要借助mousedown/mousemove/mouseover/mouseout/mouseup等鼠标事件来完成,HTML5中拖放API ...

  2. elasticsearch ik中文分词器的安装配置使用

    安装步骤  https://github.com/medcl/elasticsearch-analysis-ik 以插件形式安装: [elsearch@localhost elasticsearch- ...

  3. Linux网络知识

    在思科上面模拟一下数据包的传递过程:一般上网使用的协议是tcp 交换机是一个2层的设备,它和Ip地址是没有关系的. 交换机上主要处理的是硬件地址(MAC),它只能分析到硬件地址,再到IP地址它就不管了 ...

  4. GridControl详解(五)设置行备注和行号

    备注显示设置 设置备注字段 显示结果: 可以写入按键事件F3,用以开关备注显示 private void Form4_KeyUp(object sender, KeyEventArgs e) { if ...

  5. 集合框架小结-Collection

    1.集合框架作为处理对象的容器存在,基本接口是Collection,相对于数组而言的话,集合框架只能存储对象,但是长度是可变的.集合框架的关系图如下: 主要的内容是list.set.map, List ...

  6. 【BZOJ】2406 矩阵

    [算法]二分+有源汇上下界可行流 [题解]上下界 题解参考:[BZOJ2406]矩阵(二分+有源汇有上下界的可行流) #include<cstdio> #include<algori ...

  7. 【BZOJ】1036 [ZJOI2008]树的统计Count

    [算法]树链剖分+线段树 [题解]模板题,见http://www.cnblogs.com/onioncyc/p/6207462.html 调用线段数时要用新编号pos[i] !!! #include& ...

  8. HOMEWORK-2

    没什么超乎常人的技能吧,我想.关于C的学习之前一直是自学,上了大学也是吃老底(上一篇提到了),因为这个学期一直在学matlab,C除了帮人写过作业教过课自己也没写点什么. 指针的概念还算清楚,毕竟经常 ...

  9. laravel 模糊查询

    模糊查询: Model::where('field_name','like','%'.$keywords.'%')->get() 转载:http://wenda.golaravel.com/qu ...

  10. 【译】msfvenom

    原文链接:MSFvenom 1.使用MSFvenom命令行界面 msfvenom是Msfpayload和Msfencode的组合,将这两个工具集成在一个框架实例中. msfvenom的优点是: 一个单 ...