POJ 3660 Cow Contest (闭包传递)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7690 | Accepted: 4288 |
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 刚才学了下闭包传递,简单来说就是用Floyd来求两点是否连通。这题里,如果一点的入度加上出度等于N-1,那么就可确定这点的等级,因为除了它自己之外的所有节点要么在它之前要么在它之后,不管它前面的节点后后面的节点怎么排序,都不会影响到它。
#include <iostream>
#include <cstdio>
using namespace std; const int SIZE = ;
int N,M;
int IN[SIZE],OUT[SIZE];
bool G[SIZE][SIZE]; int main(void)
{
int from,to;
int ans; while(scanf("%d%d",&N,&M) != EOF)
{
fill(&G[][],&G[N][N],false);
for(int i = ;i <= N;i ++)
IN[i] = OUT[i] = ; for(int i = ;i < M;i ++)
{
scanf("%d%d",&from,&to);
G[from][to] = true;
} for(int k = ;k <= N;k ++)
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
G[i][j] = G[i][j] || G[i][k] && G[k][j];
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
if(G[i][j])
{
IN[j] ++;
OUT[i] ++;
} ans = ;
for(int i = ;i <= N;i ++)
if(IN[i] + OUT[i] == N - )
ans ++;
printf("%d\n",ans);
} 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
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 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 (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
随机推荐
- Redis总结(五)缓存雪崩和缓存穿透等问题
前面讲过一些redis 缓存的使用和数据持久化.感兴趣的朋友可以看看之前的文章,http://www.cnblogs.com/zhangweizhong/category/771056.html .今 ...
- TCP连接(Time_Wait、Close_Wait)说明
修改Time_Wait和CLOSE_WAIT时间 修改Time_Wait参数的方法 (在服务端修改)Windows下在HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlS ...
- Linux 卸载Oracle 11G
卸载oracle11G数据 1.使用SQL*PLUS停止数据库[oracle@OracleTest oracle]$ sqlplus /nologSQL> connect / as sysdba ...
- CSS3+Js制作的一款响应式导航条
今天制作了一个响应式导航条,能够自动随着不同的屏幕分辨率或浏览器窗口大小的不同而改变导航条的样式,这里主要用到的就是CSS3的Media Query.具体可以查看浅谈响应式布局这篇文章,这里就不花费大 ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
- Android 中View的绘制机制源代码分析 三
到眼下为止,measure过程已经解说完了,今天開始我们就来学习layout过程.只是在学习layout过程之前.大家有没有发现我换了编辑器,哈哈.最终下定决心从Html编辑器切换为markdown编 ...
- 初识ASP.NET---若干常见错误
近期在学习ASP.NET的相关知识,期间遇到了一些错误,比較常见的错误总结了一下,希望此文能给ASP.NET刚開始学习的人一些帮助.同一时候记录这些错误也方便今后自己查看. 1. GridView& ...
- AR增强现实 Augmented Reality
增强现实(Augmented Reality,简称 AR),是一种实时地计算摄影机影像的位置及角度并加上对应图像的技术,这样的技术的目标是在屏幕上把虚拟世界套在现实世界并进行互动.这样的技术最早于19 ...
- mysql 线程级别的缓冲区
线程栈信息使用内存(thread_stack) 主要用来存放每一个线程自身的标识信息,如线程id,线程运行时基本信息等等,我们可以通过 thread_stack 参数来设置为每一个线程栈分配多大的内存 ...
- 安装apache2.4.10
一:依赖安装:apache依赖于apr,apr-util,pcre,所以需要先安装他,并且需要最新的 apr官网:http://apr.apache.org/download.cgi pcre官网:h ...