POJ 3660 Cow Contest【floyd】
题目链接:
http://poj.org/problem?id=3660
题目大意:
给出n头牛,m个关系,关系为a的战力比b高。求最后可以确定排名的牛的数量
思路:
1.如果一头牛跟其他所有牛都确定了一个输赢关系,那么该牛的排名就得到了确定,所以用floyd跑一遍传递闭包。然后求得每个点的出度(赢了), 入度(输了)。若该点的度之和为 n - 1 ,即确定排名。
#include<stdio.h>
#include<string.h>
#define mem(a, b) memset(a, b, sizeof(a))
const int MAXN = ; int n;
int map[MAXN][MAXN]; //表示i赢j
int in[MAXN], out[MAXN]; void floyd()
{
for(int k = ; k <= n; k ++)
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
if(map[i][k] && map[k][j])
map[i][j] = ;
} int main()
{
int m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
map[a][b] = ;
}
floyd();
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
if(map[i][j])
{
out[i] ++;
in[j] ++;
}
int ans = ;
for(int i = ; i <= n; i ++)
if(out[i] + in[i] == n - )
ans ++;
printf("%d\n", ans);
return ;
}
POJ 3660 Cow Contest【floyd】的更多相关文章
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- POJ 3660 Cow Contest【Floyd 传递闭包】
传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...
- 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 (Floyd)
http://poj.org/problem?id=3660 题目大意:n头牛两两比赛经过m场比赛后能判断名次的有几头可转 化为路径问题,用Floyd将能够到达的路径标记为1,如果一个点能 够到达剩余 ...
- (中等) POJ 3660 Cow Contest,Floyd。
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- poj 3660 Cow Contest (bitset+floyd传递闭包)
传送门 解题思路 考试题,想到传递闭包了,写了个O(n^3)的,T了7个点...后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32) #inc ...
随机推荐
- 边学边体验django--表格
在模板的末尾,我们增加一个rlt记号,为表格处理结果预留位置. 表格后面还有一个{% csrf_token %}的标签.csrf全称是Cross Site Request Forgery.这是Djan ...
- HTML的基础
HTML:超文本标记语言 超文本包括:文字.图片.音频.视频.动画等 流程:写好HTML代码后通过浏览器(自动编译HTML代码)展现出效果 HTM ...
- leetcode解题报告(9):Implement strStr()
描述 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if nee ...
- JS 的 new 到底是干什么的?
大部分讲 new 的文章会从面向对象的思路讲起,但是我始终认为,在解释一个事物的时候,不应该引入另一个更复杂的事物. 今天我从「省代码」的角度来讲 new. --------------------- ...
- scrapy框架之shell
scrapy shell scrapy shell是一个交互式shell,您可以在其中快速调试 scrape 代码,而不必运行spider.它本来是用来测试数据提取代码的,但实际上您可以使用它来测试任 ...
- 未能加载文件或程序集“Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken...
刚开始看老师 用VS新建一个“ADO.NET 实体数据模型” 但是一直报错:未能加载文件或程序集“Microsoft.SqlServer.Management.Sdk.Sfc, Version=11. ...
- js/jQuery中的宽高
一.和window有关的宽高 window.innerWidth:浏览器窗口宽度 window.innerHeight:浏览器窗口高度(不包括导航,工具栏等的高度) window.outerWidth ...
- Ryu控制器编程开发——packet_in和packet_out简易交换机实现
Ryu控制器二次开发,实现一个简单的只能够简单地广播数据包的交换机. from ryu.base import app_manager from ryu.controller import ofp_e ...
- IE与其他浏览器兼容性问题总结
1.eval(idName) [问题描述]:IE.safari.Chrome浏览器下都可以使用eval(idName)或getElementById(idName)来取得id为idName的HTML对 ...
- linux安装puppeteer
1.安装 下载淘宝镜像的,可以同时下载puppeteer和chromium下面两条语句即可 npm install -g cnpm --registry=https://registry.npm.ta ...