POJ:3660 Cow Contest (传递闭包 + Floyd)
POJ 3660 http://poj.org/problem?id=3660
思路:
输入A > B,那么我们可以建立一套A —>B 的边。 然后求出传递闭包。
判断一个人是否知道排名,如果知道大于它的人数+小于它的人数 == n-1那么就可以知道排名了。
大于它的人数: g[u][v] 代表u 的等级大于 v (g[u][v] == 1代表有边)
小于它的人数:g[v][u] 代表v 的等级大于v
Floyd代码实现
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 100 + 5;
int n, m, u, v;
bool g[N][N];
void floyd() {
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
g[i][j] |= g[i][k] & g[k][j];
}
int main() {
freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> u >> v;
g[u][v] = 1;
}
floyd();
int ans = 0;
for (int i = 1; i <= n; ++i) {
int cnt = 0;
for (int j = 1; j <= n; ++j)
if (g[j][i] || g[i][j])cnt++;
if (cnt == n - 1)++ans;
}
cout << ans << endl;
return 0;
}
POJ:3660 Cow Contest (传递闭包 + Floyd)的更多相关文章
- 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(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.如果一头牛跟其他所有牛都确定 ...
随机推荐
- SQL 语言标准简介
版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin 一.简介 结构化查询语言(Structured Query Language)简称SQL,是一种特殊目的的编程语言,是 ...
- MATLAB时间序列数据重建与平滑:HANTS滤波
本文介绍在MATLAB中,实现基于HANTS算法(时间序列谐波分析法)的长时间序列数据去噪.重建.填补的详细方法. HANTS(Harmonic Analysis of Time Series ...
- 小程序的登录授权与退出功能(wx.getUserProfile)
一.授权登录:wx.getUserProfile 1.使用wx.getUserProfile实现登录 1.javascript: login(){ wx.getUserProfile({ desc: ...
- 【总结】MySQL使用优化
一.表设计 1.避免使用null 占用额外空间.索引无效.检索麻烦 2.能用int 不用varchaer,能用varchaer 不用text 3.int 最好给默认值 0 .varchar empt ...
- [USACO2022OPENS] Visits
题目描述 Bessie 的 \(N\)(\(2\le N\le 10^5\))个奶牛伙伴(编号为 \(1\cdots N\))每一个都拥有自己的农场.对于每个 \(1\le i\le N\),伙伴 i ...
- TCP连接断开:为什么要挥手四次
本文分享自华为云社区<解密TCP连接断开:四次挥手的奥秘和数据传输的安全>,作者: 努力的小雨 . TCP 连接断开 在当今数字化时代,互联网已经成为了人们生活中不可或缺的一部分.而在互联 ...
- Hive select查询语句
创建表 CREATE TABLE t_usa_covid19( count_date string, county string, state string, fips int, cases int, ...
- c语言指针数组和数组指针
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int main(){ 5 int a[2] ...
- STM32CubeMX教程7 TIM 通用定时器 - 输入捕获
1.准备材料 开发板(STM32F407G-DISC1) ST-LINK/V2驱动 STM32CubeMX软件(Version 6.10.0) keil µVision5 IDE(MDK-Arm) X ...
- 在终端输入EOF
在终端输入EOF 问题 如下是一个计算校验和的程序,其中使用了while循环,需要在标准输入中读取到EOF才能跳出循环. #include <stdio.h> int main(){ in ...