POJ 3660 Cow Contest(floyed运用)
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个关系,每次输入的x,y代表x胜过y,求出能够确定当前奶牛和其他所有奶牛的关系的奶牛有几头。
思路:对于每两个奶牛之间有三种关系, 1.没关系 2. a胜过b 3. a输给b,我们用dis[i][j] 代表第i只奶牛和第j只奶牛的关系。我们首先可以对开始输入的奶牛的关系建图,之后用floyed跑一遍图,遍历完所有点点之间的关系,最后判断每一个点,若与其他n-1个点都有关系则ans++
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue> using namespace std;
const int INF = 0x3f3f3f3f;
int dis[][];
int n, m;
void floyed()
{
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++) {
if ((dis[i][k] == && dis[k][j] == ) || (dis[i][k] == && dis[k][j] == ))
dis[i][j] = dis[i][k]; //判断ij之间的关系
}
}
int main()
{
ios::sync_with_stdio(false);
while (cin >> n >> m) {
memset(dis, , sizeof(dis));
for (int a, b, i = ; i <= m; i++) {
cin >> a >> b;
dis[a][b] = ;//a胜b
dis[b][a] = ;//a输给b
}
floyed();
int ans = ;
for (int i = ; i <= n; i++) {
int cnt = ;
for (int j = ; j <= n; j++) {
if (i == j)continue;
if (dis[i][j])cnt++;
}
if (cnt == (n - ))ans++;
}
cout << ans << endl;
}
return ;
}
POJ 3660 Cow Contest(floyed运用)的更多相关文章
- 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 ...
- POJ 3660 Cow Contest
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
随机推荐
- JMeter 参数意义
样本数目:运行时得到的取样器响应结果个数 最新样本:最近一个取样器结果的响应时间 平均:所有取样器结果的响应时间平均值 偏离:所有取样器结果的响应时间标准差 吞吐量:每分钟响应的取样器结果个数 中值: ...
- 2019.10.17beta
import socket import subprocess import os server = socket.socket() server.bind( ('127.0.0.1',8888) ) ...
- Spring_MVC
SpringMVC处理流程 分析: M-Model 模型(完成业务逻辑:有javaBean构成,service+dao+entity) V-View 视图(做界面的展示 jsp,html……) C- ...
- 1.Golang开山篇,GO就是NB!
目录:GO就是NB GO sb吗 安装环境 GO就是NB,K2R三位大佬写的GO,学GO不吃亏! (1)我们为什么要学 高并发 深度 || 广度 (2)go学习思路和目标 多打多练 掌握go语言 做一 ...
- nodeJs学习-13 router
const express=require('express'); var server=express(); //目录1:/user/ var routeUser=express.Router(); ...
- phpexcel使用说明2
转自:http://serisboy.iteye.com/blog/1928139 首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPE ...
- 手动实现一个form组件
最近研究了一下element-ui,想着手动实现一下里面的form组件,贴个组件里面的代码 <el-form :model="ruleForm" status-icon :r ...
- dva框架简单描述使用
首先传统的create-router-app脚手架生成的脚手架我们写仓库的时候用reducers进行调用还有thunk进行异步操作的时候,需要多层函数进行调用,这样会让我们代码进行维护的时候变得麻烦, ...
- SQL注入原理讲解,很不错!
SQL注入原理讲解,很不错! 原文地址:http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html 1.1.1 摘要 日前,国内最大的程序员 ...
- @loj - 2288@「THUWC 2017」大葱的神力
目录 @description@ @solution@ @data - 1@ @data - 2@ @data - 3@ @data - 4@ @data - 5@ @data - 6@ @data ...