POJ 3660 Cow Contest 传递闭包确定名次

2024-06-15 11:58

本文主要是介绍POJ 3660 Cow Contest 传递闭包确定名次,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目来源:POJ 3660 Cow Contest

题意:n头牛 下面m行 每行x y 代表牛x打败了牛y 问有几头牛的最终排名是确定的

思路:传递闭包 如果x打败了y 令a[x][y]=1 并且a[y][x]=-1 其他不知道的都为0  然后floyd

最后对于每头牛数一下是否有n-1个1或者-1(就是不为0) 如果有n-1个不为0 说明该牛和其他牛都确定了状态

#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
using namespace std;
const int maxn = 110;
int a[maxn][maxn];
int n, m;void floyd()
{for(int k = 1; k <= n; k++)for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++){if(a[i][k]  == -1  && a[k][j] == -1)a[i][j] = -1;if(a[i][k]  == 1  && a[k][j] == 1)a[i][j] = 1;}
}int main()
{scanf("%d %d", &n, &m);while(m--){int u, v;scanf("%d %d", &u, &v);a[u][v] = 1;//赢 a[v][u] = -1;//输 }floyd(); int ans = 0;for(int i = 1; i <= n; i++){int cnt = 0;for(int j = 1; j <= n; j++){if(i == j)continue;if(a[i][j])cnt++;}if(cnt == n-1){ans++;//printf("%d\n", i);}}printf("%d\n", ans);return 0;
}


 

这篇关于POJ 3660 Cow Contest 传递闭包确定名次的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1063393

相关文章

Closures(闭包)

Closures(闭包) 本节主要讲groovy中的一个核心语法:closurs,也叫闭包。闭包在groovy中是一个处于代码上下文中的开放的,匿名代码块。它可以访问到其外部的变量或方法。 1. 句法 1.1 定义一个闭包 { [closureParameters -> ] statements } 其中[]内是可选的闭包参数,可省略。当闭包带有参数,就需要->来将参数和闭包体相分离。

poj 3882(Stammering Aliens) 后缀数组 或者 hash

后缀数组:  构建后缀数组,注意要在字符串莫末尾加上一个没出现过的字符。然后可以2分或者直接扫描,直接扫描需要用单调队列来维护 VIEW CODE #include<cstdio>#include<algorithm>#include<iostream>#include<cmath>#include<queue>#include<stack>#include<string

poj 3294(Life Forms) 2分+ 后缀数组

我曾用字符串hash写,但是超时了。只能用后最数组了。大致思路:用不同的符号吧字符串连接起来,构建后缀数组,然后2分答案,依次扫描后缀数组,看是否瞒住条件。 VIEW CODE #include<cstdio>#include<vector>#include<cmath>#include<algorithm>#include<cstring>#include<cassert>#

poj 2391 Ombrophobic Bovines (网络流)

这是一道很经典的网络流的题目。首先我们考虑假如我们的时间为无穷大。我们吧每个点拆成2个点 i和i' .。虚拟源点s和汇点t。对于每个点建边(s,i, a[i])  (i‘,t,ib[i]) 。 其中a[i]为给点有多少牛,b[i]为容量。i和j连通 建边 (i,j',inf);如果最大流==所有牛的个数,就可能装下所有的牛。那么现在我们考虑时间。假设最大时间为T.那么如果i到j的的最短时间>T

poj 1330 LCA 最近公共祖先

水题目。直接上代码了。 VIEW CODE #include<cstdio>#include<algorithm>#include<iostream>#include<cmath>#include<queue>#include<stack>#include<string>#include<cstring>#include<map>#include<vector>#

poj 3160 Father Christmas flymouse 强连通+dp

首先我们可以确定的是,对于val值小于0的节点都变成0.   假设一个集合内2个房间都能任意到达,那么我就可以吧集合内的所有点的价值都取到,并且可以达到任一点。实际上集合内的每个点是相同的,这样的集合就是一个强连通分量。 那么我们就可以用tarjin算法进行强连通缩点, 最后形成一个dag的图。在dag的图上面进行dp。可以先用拓扑排序后dp。或者建反响边记忆化搜索 。 VIEW

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee

Codeforces April Fools Day Contest 2013

2013年愚人节的坑题。。。 A. Mysterious strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Input The input contains a sin

Maven的依赖传递、依赖管理、依赖作用域

在Maven项目中通常会引入大量依赖,但依赖管理不当,会造成版本混乱冲突或者目标包臃肿。因此,我们以SpringBoot为例,从三方面探索依赖的使用规则。 1、 依赖传递 依赖是会传递的,依赖的依赖也会连带引入。例如在项目中引入了spring-boot-starter-web依赖: <dependency><groupId>org.springframework.boot</groupId>

C#启动另外一个C#程序,并传递参数

第一个程序:             using System.ComponentModel; using System.IO;         private void button1_Click(object sender, EventArgs e)         {             string target = Path.GetDirectory