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.如果一头牛跟其他所有牛都确定 ...
随机推荐
- STM32CUBEMX入门学习笔记1:软件的简单介绍
STM32CUBEMX是ST公司设计的一款免费软件,软件可以通过其官网下载.现在已经下载到.通过STM32CUBEMX可以完成从单片机选型,程序初始化,中断配置……工作.并生成对应的"HAL ...
- pandas-Notes1
#coding = utf-8 import pandas as pd import numpy as np import matplotlib as plt # series, like vecto ...
- linux系统装载ELF过程
参考:程序员的自我修养 fork -->execve() //----kenerl space--------------- sys_execve() /*arch\i386\kernel\pr ...
- dwr介绍及配置
DWR 编辑 DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站.它可以允许在浏览器里的 ...
- Java连接Access数据库的那些坑
Java 使用 JDBC 连接Access数据库 需要掌握的技能 1.Java SE基本技术 2.懂点JDBC技术 能够学到如何使用Java正确的连接JDBC 环境 window8.1 64位 jdk ...
- xcode各个版本下载 xcode7 xcode6 xcode5
登录开发者帐号,选择 support,然后操作如下图: 登录开发者帐号,选择 support,然后操作如下图: 登录开发者帐号,选择 support,然后操作如下图: 登录开发者帐号,选择 suppo ...
- 大数据学习——SparkStreaming整合Kafka完成网站点击流实时统计
1.安装并配置zk 2.安装并配置Kafka 3.启动zk 4.启动Kafka 5.创建topic [root@mini3 kafka]# bin/kafka-console-producer. -- ...
- js中的原型哲学思想
https://segmentfault.com/a/1190000005824449 记得当年初试前端的时候,学习JavaScript过程中,原型问题一直让我疑惑许久,那时候捧着那本著名的红皮书,看 ...
- ccna 闫辉单臂路由 和 acl access control list
ccna 闫辉单臂路由 和 acl access control list 一单臂路由 当前园区网设计很少用到 成本低 小型的.局域网可用 二ACL acc ...
- Python IO多路复用select模块
多路复用的分析实例:服务端.客户端 #服务端配置 from socket import * import time import select server = socket(AF_INET, SOC ...