POJ - 3660 Cow Contest(flod)
题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的。
分析:
1、a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所有牛的大小关系都存入a。
2、对于每一头牛,cntfront表示比它强的牛的个数,cntrear表示比它弱的牛的个数,若两者相加等于N-1,那该牛的名次自然可以确定。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){if(fabs(a - b) < eps) return 0;return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN][MAXN];
int ans;
int N, M;
int solve(){for(int i = 1; i <= N; ++i){int cntfront = 0, cntrear = 0;for(int j = 1; j <= N; ++j){if(a[j][i]) ++cntfront;if(a[i][j]) ++cntrear;}if(cntfront + cntrear == N - 1) ++ans;}return ans;
}
int main(){scanf("%d%d", &N, &M);for(int i = 0; i < M; ++i){int u, v;scanf("%d%d", &u, &v);a[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(a[i][k] && a[k][j]) a[i][j] = 1;}}}printf("%d\n", solve());return 0;
}
转载于:https://www.cnblogs.com/tyty-Somnuspoppy/p/6480016.html
POJ - 3660 Cow Contest(flod)相关推荐
- 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 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- [传递闭包]POJ#3660 Cow Contest
题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...
- POJ 3660 Cow Contest
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- poj 3660 Cow Contest 传递闭包
题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...
- 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
dp,图论 题意:输入n和m表示n个牛(从1到n标号),下面m个信息,A B,表示A牛能打赢B牛.现在要给所有的牛排名(按实力从高到低),问哪些牛的排名是可以确定的 如果知道由l个人能打赢自己,自己能 ...
最新文章
- VC中CListCtrl中的LVCOLUMN和LVITEM详细介绍
- 04-java学习-选择结构
- Qt 运用鼠标绘制多边形
- 抓包写代码模拟怎么减少重复劳动
- 创建文件夹 java_java怎么建文件夹
- 阿里云混合云管理平台发布帮您管好云
- 京东软件测试有复试没,【京东测试工程师面试】正常,不是特别的难-看准网...
- [PYTHON]python 基础笔记(1)
- android顶部标题app_name,如何写一个app通用的title
- 天天学习: 关于美资,台资和国企比较分析
- 基于java springboot垃圾分类小程序源码(毕设)
- MATLAB模糊控制解析及simulink仿真示例(附fis代码和simulink仿真slx文件以及文件使用视频)
- B001 - 基于STM32的智能生态鱼缸
- Objective-C分类 (catagory)
- UOJ #11. 【UTR #1】ydc的大树
- mac安装完mysql后关机特别慢_升级macOS Sierra 10.12 关机慢
- 数字图像处理实验八图像的傅里叶变换
- 集丰照明|如何对国内 LED 市场的增长趋势与前景预测?
- 计算机多媒体论文致谢,计算机专业论文致谢范文3篇
- Google天涯问答提问遭遇