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之Cookie和代理
cookie cookie: 获取百度翻译某个词条的结果 一定要对start_requests方法进行重写. 两种解决方案: 1. Request()方法中给method属性赋值成post2. For ...
- Leecode刷题之旅-C语言/python-28.实现strstr()
/* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...
- vuls安装记录
第一步安装go环境apt-get install golang-go(显示出错,go版本apt安装太低,apt-get purge golang-go卸载后手动安装,必须1.8.3以上) 还需将/us ...
- Spring 中的文件上传与下载控制
先创建根应用上下文配置,WebDemo/src/main/java/com/seliote/webdemo/config/RootContextConfig.java package com.seli ...
- 使用USB Key(加密狗)实现身份认证
首先你需要去买一个加密狗设备,加密狗是外形酷似U盘的一种硬件设备! 这里我使用的坚石诚信公司的ET99产品 公司项目需要实现一个功能,就是客户使用加密狗登录, 客户不想输入任何密码之类的东西,只需要插 ...
- Git初步
在多人参与开发的项目中,版本控制工具是必须的,网上有很多不错的教程,能简单使用就ok了,粘几篇教程,方便学习 首先我们要了解一些基本的概念,此处简单描述一下 (1)集中式版本控制系统: CVS.SVN ...
- 玩转VIM-札记(三)
玩转VIM-札记(三) 眨眼之间,5月就要从指间溜走,不给人一点点遐想的时间,我要赶紧抓着五月的尾巴,在博客中在添一笔.那么就还接着Vim来说吧.以Vim来为五月画上一个句号. 返璞归真 相信经过玩转 ...
- 【HNOI2008】玩具装箱TOY & 斜率优化学习笔记
题目 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为 \(1\cdots N\ ...
- 谷歌js编码规范解析
http://alloyteam.github.io/JX/doc/specification/google-javascript.xm 阅读了谷歌js编码规范,我发现了很多,js的里面很多要注意的问 ...
- Spring框架中ModelAndView、Model、ModelMap的区别
转自:http://blog.csdn.net/liujiakunit/article/details/51733211 1. Model Model 是一个接口, 其实现类为ExtendedMode ...