poj 3660Cow Contest
题目链接:http://poj.org/problem?id=3660
有n头奶牛还有m种关系a,b表示a牛逼b彩笔,所以a排名比b高
最后问你给出的关系最多能确定多少头奶牛的排名,而且给出的数据不会有矛盾
其实就是给出了一个无环的有向图,只要有一点他能跟所有点有联系那么这个点的排名就知道了。
可以用一下floyd的思想还是能简单实现的。
其实这题简单来说就是能走完所有点的路都经过哪些点,最容易想到的就是floyd求多源点的最短路
然后稍微改一下就好了。
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int n , m , a , b , mmp[110][110] , In[110] , Out[110] , counts;
bool vis[110][110];
void bfs() {
memset(vis , false , sizeof(vis));
for(int k = 1 ; k <= n ; k++) {
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
if(mmp[i][k] != 0 && mmp[k][j] != 0) {
if(!vis[i][j]) {
In[j]++;
Out[i]++;
vis[i][j] = true;
mmp[i][j] = 1;
}
}
}
}
}
for(int i = 1 ; i <= n ; i++) {
//cout << i << ' ' << In[i] << ' ' << Out[i] << endl;
if(In[i] + Out[i] == n + 1) {
counts++;
}
}
}
int main() {
cin >> n >> m;
for(int i = 1 ; i <= n ; i++) {
In[i] = 0 , Out[i] = 0;
for(int j = 1 ; j <= n ; j++) {
mmp[i][j] = 0;
}
mmp[i][i] = 1;
}
for(int i = 1 ; i <= m ; i++) {
cin >> a >> b;
mmp[a][b] = 1;
}
counts = 0;
bfs();
cout << counts << endl;
return 0;
}
poj 3660Cow Contest的更多相关文章
- poj 1719Shooting Contest
//本题大意是对于一个r*c的矩阵,每一列有两个是白色的 //如今选c个位置,要求每一行至少有一个白色的方格被选上 //每一列仅仅能选一个 //用二分匹配求出最大匹配,假设最大匹配等于r,则满足 // ...
- POJ 3204 Ikki's Story I - Road Reconstruction
Ikki's Story I - Road Reconstruction Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 7 ...
- POJ 3744 Scout YYF I
分段的概率DP+矩阵快速幂 Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- [最近公共祖先] POJ 3728 The merchant
The merchant Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4556 Accepted: 1576 Desc ...
- POJ 3278 The merchant
传送门 Time Limit: 3000MS Memory Limit: 65536K Description There are N cities in a country, and there i ...
- Scout YYF I(POJ 3744)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5565 Accepted: 1553 Descr ...
- poj 3744 Scout YYF I (矩阵)
Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...
- [POJ 3734] Blocks (矩阵高速幂、组合数学)
Blocks Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3997 Accepted: 1775 Descriptio ...
- poj 3728 The merchant(LCA)
Description There are N cities in a country, and there is one and only one simple path between each ...
随机推荐
- codeforces 322 B Ciel and Flowers
题目链接 有红绿蓝三种颜色的画,每种拿三朵可以组成一束花,或者各拿一朵组成花束,告诉你每种花的数目,求出可能组成最多的花束. 如果你的代码过不了,考虑一下 8 8 9这种组合. 因为数据量很大,我的 ...
- JAVA常用的集合类
package com.xian.test; import java.util.ArrayList; import java.util.Enumeration; import java.util.Ha ...
- shardingjdbc 强制路由走主库查询实时数据 避免主从同步数据延迟
@Beanpublic shardingsphere.demo.entity.Order order(){ shardingsphere.demo.entity.Order order=new Ord ...
- JS判断字符串长度,结合element el-input el-form 表单验证(英文占1个字符,中文汉字占2个字符)
首先看看判断字符串长度的几种方法(英文占1个字符,中文汉字占2个字符) 方法一: function strlen(str) { var len = 0; for (var i = 0; i < ...
- (十二)c#Winform自定义控件-分页控件
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- linux环境下测试环境搭建
一.linux环境下测试环境搭建过程简述: 1.前端后台代码未分离情况下: 主要步骤为:安装jdk,安装mysql,安装tomcat,将项目代码部署到tomcat/webapps/下. 2.前端后台代 ...
- 大白话5分钟带你走进人工智能-第36节神经网络之tensorflow的前世今生和DAG原理图解(4)
目录 1.Tensorflow框架简介 2.安装Tensorflow 3.核心概念 4.代码实例和详细解释 5.拓扑图之有向无环图DAG 6.其他深度学习框架详细描述 6.1 Caffe框架: 6.2 ...
- Flink的Job启动JobManager端(源码分析)
通过前面的文章了解到 Driver将用户代码转换成streamGraph再转换成Jobgraph后向Jobmanager端提交 JobManager启动以后会在Dispatcher.java起来RPC ...
- C/C++ 修改系统时间,导致sem_timedwait 一直阻塞的问题解决和分析
修改系统时间,导致sem_timedwait 一直阻塞的问题解决和分析 介绍 最近修复项目问题时,发现当系统时间往前修改后,会导致sem_timedwait函数一直阻塞.通过搜索了发现int sem_ ...
- 设计模式(C#)——02工厂模式
推荐阅读: 我的CSDN 我的博客园 QQ群:704621321 在简单工厂模式中讲到简单工厂模式的缺点:难以扩展,一旦添加新运算就必须修改简单工厂方法. 工厂方法模式: ...