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 ...
随机推荐
- hdu1811 Rank of Tetris 并查集+拓扑排序
#include <stdio.h> #include <string.h> #include <vector> #include <queue> us ...
- SQL 实战语句(9)
1.如何同步根据部门表同步另外一个项目表的部门字段 update A set A.auditownerid=(select lp.epleaderId from (select ep.userid a ...
- 牛客练习赛25-A-因数个数和
题目描述 q次询问,每次给一个x,问1到x的因数个数的和. 输入描述: 第一行一个正整数q:接下来q行,每行一个正整数x 输出描述: 共q行,每行一个正整数表示答案 输入 4 1 2 3 10 输出 ...
- h5-18-文件上传
参考博客地址:https://developer.mozilla.org/zh-CN/docs/Web/API/FormData/Using_FormData_Objects 参考博客地址:http: ...
- CentOS Linux下MySQL 5.1.x的安装、优化和安全配置
下载页面:http://dev.mysql.com/downloads/mysql/5.1.html#downloads 到页面底部,找到Source downloads,这个是源码版本,下载第1个T ...
- .net 音频转换 .amr 转 .mp3 (七牛转换法)
.amr 用于移动设备的音频,压缩比比较大,多用于人声.通话,效果还行!所以,移动设备多采用amr格式来进行录存!比较常见的例子:通话录音,微信语音以及录音等! 这个鬼,用两个字来形容,就是“蛋疼”: ...
- Castle.net
using System; using System.Collections.Generic; using System.Linq;using System.Text;using Castle.Act ...
- AJPFX分享eclipse自动生成java注释方法
设置方法介绍:eclipse中:Windows->Preferences->Java->Code Style->Code Template->Comments,然后对应的 ...
- 模拟ssh的远程网络传输
粘包产生的原因分析: 第一点:客户端向服务端发起命令请求,服务端接受命令请求,并返回对应的信息,如果信息过大,客户端一次接受不了,那么下一次请求依然返回 上一个命令的内容,就出现了粘包的情况. 第二点 ...
- Java堆分配参数总结
与Java应用程序堆内存相关的JVM参数有: -Xms:设置Java应用程序启动时的初始堆大小 -Xmx:设置Java应用程序能获得的最大堆大小 -Xss:设置线程栈的大小 -XX:MinHeapFr ...