题目链接:http://poj.org/problem?id=3660

Cow Contest
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 ≤ NA ≠ 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

 
 
 
题解:
1.建图:如果A>B,则A—>B建一条边(B—>A也可以,但只能规定方向地建一条边)。
2.用Floyd求出传递闭包。
3.对于当前点X,如果与剩下的n-1个点都有联系,那么X的位置是可以确定的。
 
 
 
 
代码如下:
 #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);
}
}

最新文章

  1. 命名sql数据集
  2. Nginx中的进程亲和性 affinity
  3. SDWebImage ReadMe.md文档简单说明
  4. empty与isset的一点使用体会
  5. 低功耗蓝牙4.0BLE编程-nrf51822开发(9)
  6. [原创]java WEB学习笔记78:Hibernate学习之路---session概述,session缓存(hibernate 一级缓存),数据库的隔离级别,在 MySql 中设置隔离级别,在 Hibernate 中设置隔离级别
  7. Codeforces Round #312 (Div. 2) E. A Simple Task
  8. JSON对象和String之间的互转及处理
  9. Myeclipse提示失效?
  10. git pull冲突解决
  11. POJ - 1185 炮兵阵地 (状态压缩)
  12. 九度OJ 1065 输出梯形 (模拟)
  13. latex表格线的颜色设置(边框添加颜色)
  14. React Native如何添加自定义图标
  15. python文件的路径问题补充上一篇内容
  16. CSS元素(文本、图片)水平垂直居中方法
  17. webstorm显示行号,结构预览
  18. Go Example--闭包
  19. 读取excel表格以及生成自动化报告
  20. nginx 413 500报错

热门文章

  1. Codeforces963D. Frequency of String
  2. Lumia 1020 诞生:诺基亚拍照技术的一次狂欢
  3. [转]JVM 堆内存设置原理
  4. vue之条件渲染
  5. python多线程(二)
  6. UVA 11346 Probability
  7. Loj #6307. 「雅礼国庆 2017 Day1」Clique
  8. BZOJ3786 星际探索
  9. [转] 一句shell命令搞定代码行数统计
  10. 【从零学习openCV】IOS7下的openCV开发起步(Xcode5.1.1&amp;amp;openCV2.49)