POJ3660:Cow Contest(Floyd传递闭包)
Cow Contest
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16941 | Accepted: 9447 |
题目链接:http://poj.org/problem?id=3660
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 ≤ N; A ≠ 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场比赛,然后给出m场比赛的胜负关系,问有多少只牛能确定它们自己的名次。
题解:
这个题有点像拓扑排序,但是只用拓扑序并不能保证结果的正确性。
其实解这个题我们只需要发现这样一个关系就好了,若一只牛的名次能够被确定,那么它赢它的牛和它赢的牛个数之和为n-1。
利用这个关系,我们floyd传递闭包预处理一下,然后判断一下数量关系就好了。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int N = , M = ;
int n,m;
int mp[N][N];
int main(){
scanf("%d%d",&n,&m);
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++){
mp[i][j]=(mp[i][j]|(mp[i][k]&mp[k][j]));
}
}
}
int ans=;
for(int i=;i<=n;i++){
int win=,lose=;
for(int j=;j<=n;j++){
if(mp[i][j]) win++;
if(mp[j][i]) lose++;
}
if(win+lose==n-) ans++;
}
cout<<ans;
return ;
}
POJ3660:Cow Contest(Floyd传递闭包)的更多相关文章
- POJ3660——Cow Contest(Floyd+传递闭包)
Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- POJ3660 Cow Contest —— Floyd 传递闭包
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ-3660 Cow Contest Floyd传递闭包的应用
题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...
- POJ3660 Cow Contest floyd传递闭包
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ-3660.Cow Contest(有向图的传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17797 Accepted: 9893 De ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
随机推荐
- Scrapy框架的初步使用
Scrapy scrapy框架是一个非常全面的爬虫框架,可以说是爬虫界的django了,里面有相当多的组件,格式化组件item,持久化组件pipeline,爬虫组件spider 首先我们要先和djan ...
- Leecode刷题之旅-C语言/python-100相同的树
/* * @lc app=leetcode.cn id=100 lang=c * * [100] 相同的树 * * https://leetcode-cn.com/problems/same-tree ...
- UVA - 12230
#include <bits/stdc++.h> using namespace std; int n; double d; double p,l,v,ret,sum; ; /* 村庄A, ...
- GET TIME
基本形式 GET TIME [FIELD tim]. オプション: ... FIELD tim 機能 FIELD オプションを使用しない場合. 日付および時刻のシステム項目 sy-datlo.sy-d ...
- The Road to learn React书籍学习笔记(第四章)
高级React组件 本章将重点介绍高级 React 组件的实现.我们将了解什么是高阶组件以及如何实现它们.此外,我们还将深入探讨 React 中更高级的主题,并用它实现复杂的交互功能. 引用 DOM ...
- python2.7练习小例子(二十三)
23):题目:求1+2!+3!+...+20!的和. 程序分析:此程序只是把累加变成了累乘. #!/usr/bin/python # -*- coding: UTF-8 -*- n = ...
- 手把手教你写css3通用动画
之前接了几个微信里的项目,类似电子邀请函,什么分析报告这样的项目, 对css3动画要求十分高,每个页面客户几乎都有天马行空的想法,或者说设计师有这样的想法.众所周知css3里的keyframe写好了就 ...
- android get cpu rate
public static int getProcessCpuRate() { try { RandomAccessFile reader = new RandomAccessFile("/ ...
- python终极篇 --- django---班级管理系统
周末没事自己写了个班级管理系统,虽然简单,但也算个前期学习的总结吧 from django.db import models # Create your models here. class Banj ...
- Laxcus大数据管理系统2.0(4)- 第一章 基础概述 1.3 节点
1.3 节点 按照我们给Laxcus集群的设计定义,Laxcus集群被分为内部和外部两个网络环境.内部网络由集群的所有权人负责实施和管理,为保证集群能够有效可靠运行,需要遵守一系列的集群部署和管理规定 ...