POJ 3660 Cow Contest(求图的传递性)
题意:
给定n头牛, 然后有m个比较, 求出有多少头牛能确定自己的排名。
分析:
假设有一头牛a, 有ki头牛强于自己, kj头牛弱于自己, ki + kj == n-1时, 那么这头牛的排名就确定了。
对于每个比较建一条有向边
求出a点可达哪些点, 哪些点可达a点即可
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define _rep(i,a,b) for(int i = a; i <= b; i++)
using namespace std;
const int maxn = ;
const int inf = 1e9;
int G[maxn][maxn];
int n , m;
int main()
{
while(~scanf("%d %d", &n, &m)){
rep(i,,maxn) rep(j,,maxn) G[i][j] = ; rep(i,,m) {
int u, v;
scanf("%d %d", &u, &v);
G[u][v] = ;
}
for(int k = ; k <= n; k++){
for(int i = ; i <= n; i++){
for(int j = ; j <= n; j++){
if(G[i][j] == ) G[i][j] = G[i][k] && G[k][j]; //只有当 G[i][k] && G[k][j] 都有路时, G[i][j]才算联通
}
}
}
int ans = ;
_rep(i,,n){
int cnt = ;
_rep(j,,n){
if(G[i][j]) cnt++;
if(G[j][i]) cnt++;
}
if(cnt == 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 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
 - POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
		
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
 - 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 ...
 - POJ 3660—— Cow Contest——————【Floyd传递闭包】
		
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
 - 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 ...
 
随机推荐
- python中时间日期格式化符号的含义
			
%y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数(0-23) %I 12 ...
 - Codeforces Round #261 (Div. 2) D
			
Description Parmida is a clever girl and she wants to participate in Olympiads this year. Of course ...
 - h5-21-文件操作-读取文件内容
			
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
 - 503 Next Greater Element II 下一个更大元素 II
			
给定一个循环数组(最后一个元素的下一个元素是数组的第一个元素),输出每个元素的下一个更大元素.数字 x 的下一个更大的元素是按数组遍历顺序,这个数字之后的第一个比它更大的数,这意味着你应该循环地搜索它 ...
 - 160 Intersection of Two Linked Lists 相交链表
			
编写一个程序,找到两个单链表相交的起始节点.例如,下面的两个链表:A: a1 → a2 ↘ ...
 - G. 24  观察 + 树状数组
			
http://codeforces.com/gym/101257/problem/G 首先要看到题目,题目是本来严格大于score[i] > score[j].然后score[i] < s ...
 - MySQL5.5升级到5.6
			
5.6的新的特性 .支持GTIDs,Failover.多线程复制. 新增binlog_row_image只记录row格式下所用字段的修改(而不是像以前一样记录全部列),节省空间等资源: master. ...
 - zoj3768Continuous Login
			
链接 这题通过暴力可以看出最多不超过3 具体为什么..等着看大牛的题解. 可以预处理出来两个数之和 用bool存下 然后枚举一个数 二分剩余数的位置就可以了 勉强可过 #include <ios ...
 - poj2385 Apple Catching
			
思路: 简单dp. 实现: #include <iostream> #include <cstdio> #include <cstring> using names ...
 - 【学习笔记】深入理解js原型和闭包(2)——函数和对象的关系
			
上文(深入理解jS原型和闭包(1)——一切都是对象)已经提到,函数就是对象的一种,因为通过instanceof函数可以判断. var fn = function () { }; console.log ...