题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的。

分析:

1、a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所有牛的大小关系都存入a。

2、对于每一头牛,cntfront表示比它强的牛的个数,cntrear表示比它弱的牛的个数,若两者相加等于N-1,那该牛的名次自然可以确定。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN][MAXN];
int ans;
int N, M;
int solve(){
for(int i = 1; i <= N; ++i){
int cntfront = 0, cntrear = 0;
for(int j = 1; j <= N; ++j){
if(a[j][i]) ++cntfront;
if(a[i][j]) ++cntrear;
}
if(cntfront + cntrear == N - 1) ++ans;
}
return ans;
}
int main(){
scanf("%d%d", &N, &M);
for(int i = 0; i < M; ++i){
int u, v;
scanf("%d%d", &u, &v);
a[u][v] = 1;
}
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] && a[k][j]) a[i][j] = 1;
}
}
}
printf("%d\n", solve());
return 0;
}

  

POJ - 3660 Cow Contest(flod)的更多相关文章

  1. POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)

    POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...

  2. POJ 3660 Cow Contest

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  3. POJ 3660 Cow Contest 传递闭包+Floyd

    原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  4. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  5. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

  6. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  7. ACM: POJ 3660 Cow Contest - Floyd算法

    链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Descri ...

  8. poj 3660 Cow Contest(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

  9. POJ 3660 Cow Contest (闭包传递)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7690   Accepted: 4288 Descr ...

随机推荐

  1. 用 Weave Scope 监控集群【转】

    创建 Kubernetes 集群并部署容器化应用只是第一步.一旦集群运行起来,我们需要确保一起正常,所有必要组件就位并各司其职,有足够的资源满足应用的需求.Kubernetes 是一个复杂系统,运维团 ...

  2. vs2010编译C++ 运算符

    // CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...

  3. C++面试常见问题——10派生类的构造与析构

    派生类的构造与析构 派生类的构造 派生时构造函数与析构函数不会被继承,需要重新定义派生类的构造函数与析构函数.派生类对象包含了基类对象的值,创建派生类时首先会调用基类的构造函数,若派生类中含有其它类对 ...

  4. 云时代架构阅读笔记十五——之前碰到的Java面试题

    1.一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致. 2.Java有 ...

  5. H7-TOOL脱机烧录器功能开源发布

    H7-TOOL汇总帖:https://www.cnblogs.com/armfly/p/12283459.html 当前已经对STM32F030,STM32F103,STM32F429,STM32F7 ...

  6. linux下python开发环境的安装

    1.准备编译环境 yum groupinstall 'Development Tools' yum install zlib-devel bzip2-devel openssl-devel ncurs ...

  7. 解决d7在更高版本上运行乱码问题,或者是调用更高版本的dll

    将String类型改成WideString类型即可

  8. Django(十二)视图--利用jquery从后台发送ajax请求并处理、ajax登录案例

    一.Ajax基本概念 [参考]:https://www.runoob.com/jquery/jquery-ajax-intro.html 异步的javascript.在不全部加载某一个页面部的情况下, ...

  9. GeneWise

    GeneWise是用于将蛋白质序列进行同源预测的软件

  10. HihoCoder第十一周:树中的最长路

    #1050 : 树中的最长路 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中, ...