POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660
|
Cow Contest
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 Output * Line 1: A single integer representing the number of cows whose ranks can be determined Sample Input 5 5 Sample Output 2 Source |
题意
给你若干牛之间的优劣关系,问你有多少头牛能够被确定排名。
题解
如果有x头牛比当前牛弱,有y头牛比当前牛强,并且x+y=n-1,那么这头牛的排名就被唯一确定了。转化为图论问题,我们若牛a比牛b强,则连接a,b(单向)。运用floyd的思想,令dp[i][j]表示从i能够走到j,即牛i和牛j之间存在强弱关系,那么转移就是dp[i][j]=dp[i][j] | (dp[i][k] & dp[k][j]),跑一发floyd,再统计每个点的度即可。
代码
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define MAX_N 111
using namespace std; bool d[MAX_N][MAX_N];
int n,m; void floyd() {
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
d[i][j] = d[i][j] | (d[i][k] & d[k][j]);
} int de[MAX_N]; int main() {
cin.sync_with_stdio(false);
cin >> n >> m;
for (int i = ; i < m; i++) {
int u, v;
cin >> u >> v;
d[u][v] = ;
}
floyd();
int ans = ;
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
de[i] += d[i][j], de[j] += d[i][j];
for (int i = ; i <= n; i++)if (de[i] == n - )ans++;
cout << ans << endl;
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(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 (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
- POJ 3660 Cow Contest【Floyd 传递闭包】
传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...
- POJ 3660 Cow Contest. (传递闭包)【Floyd】
<题目链接> 题目大意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 解题分析: 首先,做这道题要明确,什么叫确定牛的排名.假设 ...
- poj 3660 Cow Contest (bitset+floyd传递闭包)
传送门 解题思路 考试题,想到传递闭包了,写了个O(n^3)的,T了7个点...后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32) #inc ...
- POJ 3660 Cow Contest(传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
- POJ 3660 Cow Contest【floyd】
题目链接: http://poj.org/problem?id=3660 题目大意: 给出n头牛,m个关系,关系为a的战力比b高.求最后可以确定排名的牛的数量 思路: 1.如果一头牛跟其他所有牛都确定 ...
随机推荐
- Shuffle UVA - 12174 尺取法
题目:题目链接 思路:见紫书,对具体操作方式还不是很理解,代码是从一个题解里看的,以后多回顾下,需要理解 代码: #include <iostream> #include <cstr ...
- Linux: 正则表达式
正则表达式:正规的表示法,常规的表示法(Regular Expression)正则表达式使用单个字符串来描述,匹配一系列的符合某个句发规则的字符串. 1)命令格式; grep [正则] 字符串 文件 ...
- Git命令大总结(纯手办)
Git完整命令手册地址:http://git-scm.com/docs PDF版命令手册地址:github-git-cheat-sheet.pdf 1.git config -l查看全局用户信息配置 ...
- python学习-- Django model -class 主键自增问题
转自:http://blog.csdn.net/mapoor/article/details/8609660 prize_id = models.IntegerField(primary_key=Tr ...
- 聊聊、Nginx 初始化日志文件
我们接着上一篇文章继续来看看 ngx_regex_init()函数.搜索 ngx_regex_init 得到位置为src/core/ngx_regex.c:ngx_regex_init(void). ...
- JAVA-字符串按指定长度换行
可能有汉字的字符串按指定长度换行. public String getStringByEnter(int length, String string) throws Exception { for ( ...
- 性能学习之六---socket接口测试
socket协议较底层,所以是一个万能协议.socket发的是数据包,所以较难看懂. 下面我们来讲解socket接口测试. 大致思路为:新建sever端和client端---建立连接---发送数据 一 ...
- IE7下z-index失效问题
看代码: HTML <div class="select-wrap"> <div class="select-name">院系</ ...
- openstack是什么?能干什么?
openstack是什么?能干什么?涉及的初衷是什么?由什么来组成?刚接触openstack,说openstack不是一个软件,而是由多个组件进行组合,这是一个更深层次的理解,当我们看到dashboa ...
- Django的标准库django.contrib包介绍
原文地址:http://www.nowamagic.net/academy/detail/1318716 前面我们激活了 Django 后台,我们要使用自动化的站点管理工具(django.contri ...