最短路(floyd) Cow Contest
来源:互联网 发布:淘宝监控软件 编辑:程序博客网 时间:2024/04/27 20:48
Cow Contest
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 69 Accepted Submission(s) : 37
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 cowA has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤B ≤ N; A ≠ B), then cow A will always beat cowB.
Farmer John is trying to rank the cows by skill level. Given a list the results ofM (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.
* 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
* Line 1: A single integer representing the number of cows whose ranks can be determined
5 54 34 23 21 22 5
2
题目分析:
1)一群牛打架,只有知接或者间接和其余所有的牛打架才能够判断名次
2)多头牛,多个源点,直接用floyd()
原因:数据量较少
3)初始化: memset(VS,0,sizeof VS);
判断: if(VS[i][k]!=0 && VS[k][j]!=0)
VS[i][j]=1;
#include<stdio.h>
#include<string.h>#define maxn 105
#define INF 0x3f3f3f3f
int VS[maxn][maxn];
int n,m;
void floyd()
{
int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(VS[i][k]!=0 && VS[k][j]!=0)
VS[i][j]=1;
}
}
int main()
{
int a,b,i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
int number=0;
int cnt;
memset(VS,0,sizeof VS);
while(m--)
{
scanf("%d%d",&a,&b);
VS[a][b]=1;
}
floyd();
for(i=1;i<=n;i++)
{
cnt=0;
for(j=1;j<=n;j++)
{
if(VS[i][j]||VS[j][i])
cnt++;
}
if(cnt==n-1)
number++;
}
printf("%d\n",number);
}
return 0;
}
- 最短路(floyd) Cow Contest
- Cow Contest [最短路][floyd]
- POJ 3660 Cow Contest 最短路floyd
- nyoj 211 Cow Contest 【最短路&&floyd】
- poj 3660 Cow Contest(最短路floyd)
- POJ 3660 Cow Contest(Floyd最短路)
- POJ-3660-Cow Contest [最短路][Floyd]
- Floyd最短路——POJ 3360 Cow Contest
- 【最短路】 Cow Contest
- 最短路(floyd) Cow Hurdles
- Cow Contest(POJ 3660)(Floyd)(任意两点间最短路)
- POJ 3613 Cow Relays Floyd最短路
- [floyd]poj3660 Cow Contest
- POJ3660 Cow Contest(floyd)
- Cow Contest(Floyd)
- Cow Contest Floyd
- 【Floyd求最短路+快速幂】PKU-3613-Cow Relays
- USACO-Section 2.4 Cow Tours(最短路[Floyd])
- 循环冗余校验码(CRC)应用总结(包括C++源码)
- C语言写的扫雷
- Android项目总结
- poj 1755 Triathlon(半平面解线性规划)
- win7,python2.7.6安装pip
- 最短路(floyd) Cow Contest
- 分析与分享 ----腾讯实习生招聘从笔试到签约
- qt+opencv+pkg-config
- JAX-WS - Soap消息的捕获
- python学习笔记二(正则表达式)
- 最短路 (Dijstra) 最短路
- [20140426]操作系统概论
- 台阶问题递归优化
- 计算机视觉、机器学习相关领域论文和源代码大集合--持续更新……