233333...

Description:

就是说呢。牛是的实力室友大小之分的。然后呢。告诉你很多pair 表示任意两头牛之间的实力大小。按实力排序之后。问你一共有多少只牛的排名是确定了的。

T_T == 坑了好多WA....应该是 =

好吧。。貌似是拓扑排序的floyd算法。。数据太小。。三重循环水过、就是判断有多少只牛的入度出度和是n-1就欧克了。。。。

代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;

int map[105][105];

int main()
{
    int n, m;
    while(cin >> n)
    {
        cin >> m;
        memset(map, 0, sizeof(map));
        for (int i=0; i<m; ++i)
        {
            int x, y;
            cin >> x >> y;
            map[x-1][y-1] = 1;
        }
        for (int k=0; k<n; ++k)
        {
            for (int i=0; i<n; ++i)
            {
                for (int j=0; j<n; ++j)
                {
                    if (map[i][k] && map[k][j])
                        map[i][j] = 1;
                }
            }
        }
        int sum = 0;
        int du[210];
        memset(du, 0, sizeof(du));
        for (int i=0; i<n; ++i)
        {
            for (int j=0; j<n; ++j)
            {
                if (map[i][j])
                {
                    du[i]++;
                    du[j]++;
                }
            }
        }
        for (int i=0; i<n; ++i)
        {
            if (du[i] == n-1)
                sum++;
        }
        cout << sum << endl;
    }
    return 0;
}

POJ 3660的更多相关文章

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

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

  2. 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 ...

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

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

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

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

  5. POJ 3660 Cow Contest

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

  6. POJ 3660 Cow Contest (Floyd)

    http://poj.org/problem?id=3660 题目大意:n头牛两两比赛经过m场比赛后能判断名次的有几头可转 化为路径问题,用Floyd将能够到达的路径标记为1,如果一个点能 够到达剩余 ...

  7. POJ 3660 Cow Contest (Floyd)

    题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...

  8. (poj 3660) Cow Contest (floyd算法+传递闭包)

    题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...

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

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

  10. POJ 3660 Cow Contest【floyd】

    题目链接: http://poj.org/problem?id=3660 题目大意: 给出n头牛,m个关系,关系为a的战力比b高.求最后可以确定排名的牛的数量 思路: 1.如果一头牛跟其他所有牛都确定 ...

随机推荐

  1. [转]ubuntu下安装程序的三种方法

    出处:http://www.cnblogs.com/xwdreamer/p/3623454.html 引言 在ubuntu当中,安装应用程序我所知道的有三种方法,分别是apt-get,dpkg安装de ...

  2. elastic

    学习链接 http://rfyiamcool.blog.51cto.com/1030776/1420811?utm_source=tuicool&utm_medium=referral

  3. Manacher 算法(hdu 3068 && hdu 3294)

    今天打算补前晚 BC 的第二题,发现要用到能在 O(n) 时间求最大回文子串长度的 Manacher 算法,第一次听,于是便去百度了下,看了大半天,总算能看懂了其思想,至于他给出的代码模板我没能完全看 ...

  4. iOS 开发之照片框架详解(2)

    一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...

  5. 使用Mozilla Firefox插件RestClient测试Http API接口

    RESTClient是Mozilla Firefox一个用于测试http请求插件.在火狐附加组件里面查询并安装,非常小巧,界面非常简单,使用非常的方便,看下面这张图你就全明白了,希望对新手有帮助! 1 ...

  6. jquery中DOM

    节点包裹 wrap() (1)$().wrap(html) 将选择的节点用指定的元素包装 $('p').wrap('<div></div>'); (2)多层包裹 $('p'). ...

  7. java中身份证号15位转18位

    /** * 将15位转换为18位 * @param idCode 15位身份证号 * @return String 18位身份证号 */ public String toEighteen(String ...

  8. js中style.display=""无效的解决方法

    本文实例讲述了js中style.display=""无效的解决方法.分享给大家供大家参考.具体解决方法如下: 一.问题描述: 在js中我们有时想动态的控制一个div显示或隐藏或更多 ...

  9. Linq分页查询

    //Linq分页查询 int pageIndex = Convert.ToInt32(HttpContext.Current.Request["PageIndex"]); int ...

  10. python 练习 7

    #!/usr/bin/python # -*- coding: utf-8 -*- def gcd(x,y): #最大公因子 if x>y:x%=y while x: x,y=y%x,x ret ...