Cow Contest/POJ 3660

Cow Contest/POJ 3660

题目

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.
题目来源:POJ 3660
题目链接

题意

有n头牛,他们的等级为1…n,(每头牛等级不一样),他们进行了M轮比拼,等级高的牛会赢,告诉你这M轮的结果,问有多少头牛的等级是可以确定地。

解法

一头牛的等级能够确定只有当它与其余n-1头牛的关系确定时才能确定,所以我们可以用M轮比拼的结果来构图,然后利用有点类似于Floyd的方法来确定牛之间的关系。

代码:

#include <stdio.h>
#include <cstring>
#include <queue> 
using namespace std;
int a[110][110],n,x,y,sum,ans,m;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) 
	{
		scanf("%d%d",&x,&y);
		a[x][y]=1;a[y][x]=-1;
	}
	for (int i=1;i<=n;i++) 
	for (int j=1;j<=n;j++) 
	for (int k=1;k<=n;k++) 
	if (!a[i][j])
	{
		if (a[i][k]==1 && a[k][j]==1) a[i][j]=1,a[j][i]=-1;
		if (a[i][k]==-1 && a[k][j]==-1) a[i][j]=-1,a[j][i]=1;
	}
	for (int i=1;i<=n;i++) 
	{
		bool flag=true;
		for (int j=1;j<=n;j++) if (!a[i][j] && i!=j) flag=false;
		if (flag) ans++;
	}
	printf("%d",ans);
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值