POJ 3660 Cow Contest
题目链接:http://poj.org/problem?id=3660
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10066 | Accepted: 5682 |
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 题目大意:有n头牛,然后有m个条件 每个条件有两个整数a,b表示a能打败b 然后问你有多少头牛能够确定名次。
解题思路:考虑到能够确定名次的牛需要满足一个条件(打败他的牛的个数加上他打败的牛的个数为n-1)
AC代码:
#include <stdio.h>
#include <string.h>
int p[][];
int n,m;
void floyd()
{
int i,j,k;
for (k = ; k <= n; k ++)
{
for (i = ; i <= n; i ++)
{
for (j = ; j <= n; j ++)
{
if (p[i][k] && p[k][j]) //间接相连也表示能够打败
p[i][j] = ;
}
}
}
}
int main ()
{
int i,j,a,b;
while (~scanf("%d%d",&n,&m))
{
memset(p,,sizeof(p)); for (i = ; i < m; i ++)
{
scanf("%d%d",&a,&b);
p[a][b] = ;
}
floyd();
int ans,sum = ;
for (i = ; i <= n; i ++)
{
ans = ;
for (j = ; j <= n; j ++)
{
ans += p[i][j]; //他打败的牛的个数
ans += p[j][i]; //打败他的牛的个数
}
if (ans == n-)
sum ++;
}
printf("%d\n",sum);
}
return ;
}
POJ 3660 Cow Contest的更多相关文章
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- 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——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
随机推荐
- 第一次编辑JAVA
其实就是根据例题来进行编辑,但并不是一次就对了的,有大小写输入出错的问题,有漏掉标点符号的问题,值得注意的是,所有的标点符号都需要是在英文输入法状态下输入的,最后的问题——例题所用的C盘给我们带来了系 ...
- hihocoder 1138 Islands Travel dijkstra+heap 难度:2
http://hihocoder.com/problemset/problem/1138 很久不用最短路,几乎连基本性质也忘了,结果这道题就是某些最短路算法空间复杂度是o(n) 这里总结四种算法 算法 ...
- 【转】Centos系统文件与用户权限分配详解ftp,nginx,php
linux系统中权限是非常完善的一个功能了,我们如果设置不正确文件就无法使用了,像我们以一般情况需要把文件权限设置为777或644了,对于用户权 限就更加了,像素ftp,nginx,php这些我们都可 ...
- android中正确导入第三方jar包
android中正确导入第三方jar包 andriod中如果引入jar包的方式不对就会出现一些奇怪的错误. 工作的时候恰好有一个jar包需要调用,结果用了很长时间才解决出现的bug. 刚开始是这样引用 ...
- 记录一些容易忘记的属性 -- UIGestureRecognize手势
//一个手势只能添加到一个view上面 //设置当前手势需要的点击次数 _tapRec.numberOfTapsRequired = 1;//(默认为1) //设置当前需要几个手指同时点击 ...
- 《Java实验四》
//实验4--附录一代码 public class PassValueTest { //静态代码块,类一加载就执行的部分. //所以运行这个程序会输出 class loding static { Sy ...
- 一个很好介绍js的例子
function UpdateInit(opt){ this.init(opt);} UpdateInit.prototype={ loadUrl:null, loadParam:null, befo ...
- 【FreeBuf视频】《安全大咖说》专访知道创宇CTO杨冀龙(watercloud)
[FreeBuf视频]<安全大咖说>专访知道创宇CTO杨冀龙(watercloud) 发布于 2016/05/16 FreeBuF.COM 杨冀龙,江湖人称watercloud,知道创宇公 ...
- ICTCLAS50中文分词软件“Init ICTCLAS failed!”问题
if (!ICTCLAS_Init(Server.MapPath("ICTCLAS50"))) { Response.Write( ...
- GNURadio For Windows编译安装脚本v1.1.1发布
GNURadio也能在Windows上运行了,安装GNURadio时,会自动化下载一系列powershell脚本,在源里进行build.然后它依赖为64位原生二进制文件,使用Visual Studio ...