POJ 3660 Cow ContestCow(Floyd传递闭包)题解
题意:给出m个关系,问你能确定机头牛的排名
思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名。
代码:
#include<cstdio> #include<set> #include<map> #include<cmath> #include<stack> #include<vector> #include<queue> #include<cstring> #include<string> #include<sstream> #include<iostream> #include<algorithm> #define ll long long using namespace std; const int maxn = 100+10; const int INF = 0x3f3f3f3f; int mp[maxn][maxn],can[maxn]; int main(){int n,m;memset(mp,0,sizeof(mp));memset(can,0,sizeof(can));scanf("%d%d",&n,&m);while(m--){int u,v;scanf("%d%d",&u,&v);mp[u][v] = 1;}for(int k = 1;k <= n;k++){for(int i = 1;i <= n;i++){for(int j = 1;j <= n;j++){if(mp[i][k] && mp[k][j]){mp[i][j] = 1;}}}}int ans = 0;for(int i = 1;i <= n;i++){for(int j = 1;j <= n;j++){if(mp[i][j] && i != j){can[i]++;can[j]++;}}}for(int i = 1;i <= n;i++){if(can[i] == n - 1) ans++;}printf("%d\n",ans);return 0; }
转载于:https://www.cnblogs.com/KirinSB/p/9486507.html
POJ 3660 Cow ContestCow(Floyd传递闭包)题解相关推荐
- POJ 3660 Cow Contest [Floyd]
POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- 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 传递闭包
题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...
- [传递闭包]POJ#3660 Cow Contest
题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...
- Cow Contest POJ - 3660(floyed求传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1-N, are participating in a programming contest. As we a ...
- POJ - 3660 Cow Contest(最短路变形+闭包传递)
题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
最新文章
- Activiti工作流实战-2
- cli3解决 ie11语法错误 vue_从零到一教你基于vue开发一个组件库高性能前端架构解决方案...
- win10内核linux,windows 10中发布完整的Linux内核
- fis3 php cgi,FIS3 : 构建
- go strconv
- matplotlib 画多条折线图且x轴下标非数值
- [react] 怎么在JSX里属性可以被覆盖吗?覆盖的原则是什么?
- proxy_pool开源项目攻克学习
- unity 存档插件_【Unity消息】5月1日到5月15日 Unity资源商店大促
- Gerrit代码Review入门实战 1
- hadoop 启动 报running beyond virtual memory错误的解决
- abab的四字成语_abab的四字词语成语
- 互联网-3互联网思维的应用
- vue 怎么销毁dom_Vue 中如何转移 Dom ?
- 谢烟客---------Linux之SELinux的基本应用
- Curl POST to HTTPS url gives SSLRead() error:curl: (56) SSLRead() return error -9806
- 《TCP/IP详解》读书笔记(18章)-TCP连接的建立与中止
- python面试自我介绍_python自我描述
- 将 MobaXterm 的高亮/突出显示集功能(HighLight sets)移植到 Xshell6 中使用
- MySQL如果不存在一个表则创建
热门文章
- 线程同步思考 - Condition模块
- spring3.0注解
- Jquery实现图片左右滚动,没有头尾的,一直循环
- sublime text3 运行lua_[电脑常识] 用这4个系统垃圾清理软件,让电脑操作系统运行如飞 !...
- gan 总结 数据增强_[NLP]聊一聊,预处理和数据增强技术
- selenium 验证码识别_如何获取验证码?
- c语言小程序跑马灯,微信小程序实现跑马灯效果(完整代码)
- java.net import_import java.net.URL;是什么类?
- python整数类型在每一台计算机上的取值范围是一样的_第四章、Python数据类型
- 记录一下利用ffmpeg将avi转为mp4