POJ3660 Cow Contest —— Floyd 传递闭包
题目链接:http://poj.org/problem?id=3660
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13085 | Accepted: 7289 |
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
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++)
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e2+; int n, m;
bool gra[MAXN][MAXN]; int main()
{
while(scanf("%d%d", &n,&m)!=EOF)
{
memset(gra, false, sizeof(gra));
for(int i = ; i<=m; i++)
{
int u, v;
scanf("%d%d", &u,&v);
gra[u][v] = true;
} for(int k = ; k<=n; k++) //求传递闭包
for(int i = ; i<=n; i++)
for(int j = ; j<=n; j++)
gra[i][j] = gra[i][j] || (gra[i][k]&&gra[k][j]); int ans = ;
for(int i = ; i<=n; i++)
{
int cnt = ;
for(int j = ; j<=n; j++)
if( gra[i][j] || gra[j][i] )
cnt++;
if(cnt==n-) //i与剩下的n-1个数都能确定关系,则i的位置确定
ans++;
} printf("%d\n", ans);
}
}
最新文章
- 命名sql数据集
- Nginx中的进程亲和性 affinity
- SDWebImage ReadMe.md文档简单说明
- empty与isset的一点使用体会
- 低功耗蓝牙4.0BLE编程-nrf51822开发(9)
- [原创]java WEB学习笔记78:Hibernate学习之路---session概述,session缓存(hibernate 一级缓存),数据库的隔离级别,在 MySql 中设置隔离级别,在 Hibernate 中设置隔离级别
- Codeforces Round #312 (Div. 2) E. A Simple Task
- JSON对象和String之间的互转及处理
- Myeclipse提示失效?
- git pull冲突解决
- POJ - 1185 炮兵阵地 (状态压缩)
- 九度OJ 1065 输出梯形 (模拟)
- latex表格线的颜色设置(边框添加颜色)
- React Native如何添加自定义图标
- python文件的路径问题补充上一篇内容
- CSS元素(文本、图片)水平垂直居中方法
- webstorm显示行号,结构预览
- Go Example--闭包
- 读取excel表格以及生成自动化报告
- nginx 413 500报错
热门文章
- Codeforces963D. Frequency of String
- Lumia 1020 诞生:诺基亚拍照技术的一次狂欢
- [转]JVM 堆内存设置原理
- vue之条件渲染
- python多线程(二)
- UVA 11346 Probability
- Loj #6307. 「雅礼国庆 2017 Day1」Clique
- BZOJ3786 星际探索
- [转] 一句shell命令搞定代码行数统计
- 【从零学习openCV】IOS7下的openCV开发起步(Xcode5.1.1&;amp;openCV2.49)