当前位置: 首页 > news >正文

(floyd+补集) poj 3275

Ranking the Cows
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 2569 Accepted: 1203

Description

Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest.

FJ has already compared the milk output rate for M (1 ≤ M ≤ 10,000) pairs of cows. He wants to make a list of C additional pairs of cows such that, if he now compares those C pairs, he will definitely be able to deduce the correct ordering of all N cows. Please help him determine the minimum value of C for which such a list is possible.

Input

Line 1: Two space-separated integers:  N and  M 
Lines 2.. M+1: Two space-separated integers, respectively:  X and  Y. Both  X and  Y are in the range 1... N and describe a comparison where cow  X was ranked higher than cow  Y.

Output

Line 1: A single integer that is the minimum value of  C.

Sample Input

5 5
2 1
1 5
2 3
1 4
3 4

Sample Output

3

Hint

From the information in the 5 test results, Farmer John knows that since cow 2 > cow 1 > cow 5 and cow 2 > cow 3 > cow 4, cow 2 has the highest rank. However, he needs to know whether cow 1 > cow 3 to determine the cow with the second highest rank. Also, he will need one more question to determine the ordering between cow 4 and cow 5. After that, he will need to know if cow 5 > cow 3 if cow 1 has higher rank than cow 3. He will have to ask three questions in order to be sure he has the rankings: "Is cow 1 > cow 3? Is cow 4 > cow 5? Is cow 5 > cow 3?"

Source

USACO 2007 March Gold
 
题意。。。给出若干大小,求还需要多少对比较使得构成一个顺序。。
补集的思想。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
vector<int> from[1001],to[1001];
int mp[1001][1001];
int n,m;
int main()
{
    int ans=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        mp[x][y]=1;
        from[x].push_back(y);
        to[y].push_back(x);
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=0;i<to[k].size();i++)
        {
            for(int j=0;j<from[k].size();j++)
            {
                int x,y;
                x=to[k][i],y=from[k][j];
                if(!mp[x][y])
                {
                    mp[x][y]=1;
                    from[x].push_back(y);
                    to[y].push_back(x);
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i!=j&&mp[i][j])
                ans++;
        }
    }
    printf("%d\n",n*(n-1)/2-ans);
    return 0;
}

  

转载于:https://www.cnblogs.com/water-full/p/4474378.html

相关文章:

  • 我大四了,oh,我要毕业了 _随笔
  • MeeGo handset 1.1开发环境[3]:直接使用Qemugl
  • Resharper
  • C++ VS C#(1):注释,变量,控制台输出
  • 我的java mvc
  • 项目管理学习笔记三:项目管理一般知识
  • Markdown——入门指南
  • 项目管理学习笔记四:项目立项管理
  • 项目管理学习笔记五:项目整体管理
  • Extreme Learning Machine(ELM)的工程哲学
  • C++ VS C#(2):字符串,命名空间
  • URAL 2032 - Conspiracy Theory and Rebranding【本源勾股数组】
  • 《BREW进阶与精通——3G移动增值业务的运营、定制与开发》连载之89——BREW中的测试工具...
  • uva 571 素数的性质
  • 《BREW进阶与精通——3G移动增值业务的运营、定制与开发》连载之90——BREW中的调试信息...
  • 深入了解以太坊
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • avalon2.2的VM生成过程
  • CentOS6 编译安装 redis-3.2.3
  • ES6 ...操作符
  • ES6 学习笔记(一)let,const和解构赋值
  • golang中接口赋值与方法集
  • mysql常用命令汇总
  • SpringBoot 实战 (三) | 配置文件详解
  • Vue 动态创建 component
  • Vue 重置组件到初始状态
  • vuex 学习笔记 01
  • Vue全家桶实现一个Web App
  • windows下如何用phpstorm同步测试服务器
  • WordPress 获取当前文章下的所有附件/获取指定ID文章的附件(图片、文件、视频)...
  • 那些被忽略的 JavaScript 数组方法细节
  • 无服务器化是企业 IT 架构的未来吗?
  • 译有关态射的一切
  • 在Docker Swarm上部署Apache Storm:第1部分
  • Prometheus VS InfluxDB
  • # .NET Framework中使用命名管道进行进程间通信
  • # 日期待t_最值得等的SUV奥迪Q9:空间比MPV还大,或搭4.0T,香
  • #1014 : Trie树
  • #我与Java虚拟机的故事#连载04:一本让自己没面子的书
  • (4)Elastix图像配准:3D图像
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (LeetCode 49)Anagrams
  • (NO.00004)iOS实现打砖块游戏(九):游戏中小球与反弹棒的碰撞
  • (超详细)语音信号处理之特征提取
  • (二十四)Flask之flask-session组件
  • (简单) HDU 2612 Find a way,BFS。
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • (转)nsfocus-绿盟科技笔试题目
  • (转载)hibernate缓存
  • ****Linux下Mysql的安装和配置
  • **登录+JWT+异常处理+拦截器+ThreadLocal-开发思想与代码实现**
  • .apk文件,IIS不支持下载解决
  • .Net CF下精确的计时器
  • .net MySql
  • .net Stream篇(六)