Cow Contest

POJ - 3660

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代表奶牛的数量,m代表m场比赛,下面m行每行有两个整数a,b,代表本场比赛a能够击败b,(注:若a能击败b,b能击败c,则代表a能击败c)问最后能确定多少头奶牛的排名。

解决方法:通过使用floyd算法,将每两头奶牛的胜负关系确定,如果知道一头奶牛与其他所有奶牛的胜负关系,则可推出这头奶牛的排名。

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e3 + 5;
const ll mod = 1e9+7;
bool mapp[maxn][maxn];
int num[maxn];
int n,m;
void floyd()
{rep(k,1,n) {rep(i,1,n) {rep(j,1,n) {if(mapp[i][k]==true&&mapp[k][j]==true)mapp[i][j]=true;}}}
}
int main()
{//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);cin>>n>>m;memset(mapp,false,sizeof(mapp));while(m--){int a,b;cin>>a>>b;mapp[a][b]=true;}floyd();int ans=0;rep(i,1,n) {rep(j,1,n) {if(mapp[i][j]==true||mapp[j][i]==true)num[i]++;}if(num[i]==n-1)ans++;}cout<<ans<<endl;return 0;
}

Cow Contest【最短路-floyd】相关推荐

  1. Cow Contest POJ - 3660 Floyd算法,关系链图

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  2. POJ - 3660 Cow Contest(最短路变形+闭包传递)

    题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...

  3. POJ 3660 Cow Contest [Floyd]

    POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...

  4. H - Cow Contest POJ - 3660(Floyd 传递闭包)

    H - Cow Contest POJ - 3660 题意: 有 n 头牛比赛,边 1 -> 2 代表 1 能赢 2 ,给你 m 条边,问能确定出多少头牛的名次? 思路: 如果 1->2 ...

  5. BZOJ 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛【Floyd】

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec Memory Limit: 64 MB Description FJ的N(1 <= ...

  6. bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛(floyd)

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1153  Solved: 7 ...

  7. POJ3660 - Cow Contest - 关系传递闭包(最短路变形)+思维

    1.题目描述: Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11280   Accepted: 6 ...

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

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

  9. poj3660 Cow Contest

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8967   Accepted: 5032 Descr ...

最新文章

  1. 显示一个数字到小数点后两位
  2. Deep Learning(深度学习)学习笔记整理系列
  3. idhttpserver的使用方法
  4. [答疑]-中断流程举例:在TEE侧时产生了FIQ,回到REE后为啥又产生了IRQ
  5. AI圈最新深度学习量化算法!
  6. python编辑器对比和推荐
  7. 后端技术:SpringBoot 中实现跨域的5种方式
  8. 微软发布VS Code Jupyter插件!不止Python!多语言的Jupyter Notebook支持来了!
  9. thinkphp php 5.2,ThinkPHP5.2:时间查询(改进、优化)
  10. 3s新闻周刊第9期,本期策划:电子地图的出路
  11. 刘德华2007新歌《一》歌词及在线试听地址
  12. php提示返回,PHP指定方法的返回类型提示
  13. Linux Workqueue
  14. 网格搜索的原理以及实战以及相关API(GridSearchCV)
  15. 黑苹果10.14版本n卡安装以及声卡驱动
  16. 【Windows】Windows设置IP与DNS(交互界面和CMD命令行)
  17. ActiveMQ集群安装与配置
  18. 微信会员卡管理系统会员充值说明
  19. python使用worldcloud模块、jieba模块做QQ消息记录词云
  20. 消防应急疏散指示系统在某居民社区综合体项目的应用

热门文章

  1. 信号槽绑定时出现未有匹配的connect()函数
  2. Python next 函数 - Python零基础入门教程
  3. oracle 执行sql,Oracle动态执行SQL
  4. java mvc数据库 封装_关于SpringMvc参数封装_JavaEE框架(Maven+SpringMvc+Spring+MyBatis)全程实战教程_Java视频-51CTO学院...
  5. matlab chan算法定位,MATLAB实现基于Chan氏算法的三维TDOA定位
  6. tos重装mysql_云服务器(腾讯云)从零开始部署记录(3)之mysql5.7安装
  7. cairosvg在linux中的安装_直接用ISO文件在linux上安装新系统
  8. 卫生系统计算机考试内容,2021年卫生资格考试题型是什么样的?一篇搞懂!
  9. 网贷大数据什么时候会好_如果人类把地球钻穿了,会发生什么?大数据分析告诉你多可怕...
  10. 维拉智能管家机器人_“女性机器人”广受欢迎,但却面临3大问题,男性坦言:不敢用...