题意:有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. Windows 10长脸了!

    Windows 10一直毁誉参半,但是在微软的持续升级完善之下,同时随着时间的流逝,已经顺利成为全球第一大桌面操作系统,并开始逐渐甩开Windows 7,全球设备安装量已经达到约8亿部. 根据最新的S ...

  2. docker 为镜像添加ssh服务-使用Dockerfile 创建

    首先,基于要添加内容的镜像ubuntu:18.04运行一个容器, 在宿主机(下面步骤是在容器中创建的,应该在宿主机创建进行以下步骤) 一.创建一个工作目录 二.创建Dockerfile 和脚本run. ...

  3. springboot整合logback集成elk实现日志的汇总、分析、统计和检索功能

    在Spring Boot当中,默认使用logback进行log操作.logback支持将日志数据通过提供IP地址.端口号,以Socket的方式远程发送.在Spring Boot中,通常使用logbac ...

  4. NFC性价比高频读卡器首选方案:FM17550

    FM17550具有低电压.低功耗.驱动能力强.多接口支持.多协议支持等特点.适用于低功耗.低电压.低成本要求的非接触读写器应用,及NFC协议兼容的NFC设备. FM17550是一款高度集成的工作在13 ...

  5. 需要多个参数输入时-----------------考虑使用变种的Builder模式

    业务需求: 创建一个不可变的Person对象,这个Person可以拥有以下几个属性:名字.性别.年龄.职业.车.鞋子.衣服.钱.房子. 要求: 其中名字和性别是必填项,而其他选填项可以根据情况自由输入 ...

  6. JDK8中的HashMap实现原理及源码分析

    大纲 一.什么是Hash?什么是HashMap? 二.HashMap的内部实现机制 1.HashMap基本元素 ①DEFAULT_INITIAL_CAPACITY&MAXIMUM_CAPACI ...

  7. php 文件缓存 include vs serialize vs json_encode

    大神:http://techblog.procurios.nl/k/news/view/34972/14863/cache-a-large-array-json-serialize-or-var_ex ...

  8. parameterType和resultType

    在MyBatis中,我们通过parameterType完成输入映射(指将值映射到sql语句的占位符中,值的类型与dao层响应方法的参数类型一致),通过resultType完成输出映射(从数据库中输出, ...

  9. 开源DDD设计模式框架YMNNetCoreFrameWork第四篇-增加YMNSession,增加异常处理,增加策略授权

    1.增加YMNSession,可以获取当前登录的用户信息 2.增加异常处理,不要使用过滤器,过滤器只能获取到mvc异常 3.增加策略授权,策略授权支持用户角色.用户名授权,初步实现 代码地址:http ...

  10. Python实战案例:这是你见过的最详细的JS加密登录某博

    0x00 抓包分析 简单的搜索之后发现,很多参数都是登陆上面这个请求返回的值,这个请求在输入完账号光标到达密码框时就会生成! 0x01 加密逻辑分析 搜索su=可以很快找到加密的位置,上图看到e.su ...