POJ 3660 Cow Contest [Floyd]

POJ - 3660 Cow Contest

http://poj.org/problem?id=3660

N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.

The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ B), then cow A will always beat cow B.

Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.

Input?
* Line 1: Two space-separated integers: N and M?
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B

Output?
* Line 1: A single integer representing the number of cows whose ranks can be determined?
 ?
Sample Input?
5 5?
4 3?
4 2?
3 2?
1 2?
2 5?
Sample Output?
2

這題就是給m個有序對,問這些有序對構成的有向圖能確定排名位置的點有幾個。

這題用floyd的最短路去做又快又方便,但是我一直用拓撲排序在寫所以就一直在WA。補題后看了網上用拓撲排序的題解,原理就是每次拓撲排序以后將未處理的連在同一點邊合并,其實也是用了floyd的思想,但是沒有直接用最短路思路清晰,而且要多一步并查集去判斷是否是一個聯通塊。

最短路做法:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;int w[105][105];int main()
{int n,m,a,b;scanf("%d%d",&n,&m);while(m--){scanf("%d%d",&a,&b);w[a][b] = 1;}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)w[j][k] = (w[j][k] > 0 || w[j][i] + w[i][k] == 2);int res = 0;for(int i=1;i<=n;i++){int tp = 0;for(int j=1;j<=n;j++)if(w[i][j] || w[j][i]) tp++;if(tp == n-1) res++;}printf("%d\n",res);}

?

轉載于:https://www.cnblogs.com/HazelNut/p/7821069.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390841.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390841.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390841.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux 網絡相關命令

1. telnet 1.1 檢查端口是否打開 執行 telnet www.baidu.com 80&#xff0c;粘貼下面的文本&#xff08;注意總共有四行&#xff0c;最后兩行為兩個空行&#xff09; telnet [domainname or ip] [port]例如&#xff1a; telnet www.baidu.com 80 如果這個網絡連接可達&…

JSON.parseObject(String str)與JSONObject.parseObject(String str)的區別

一、首先來說說fastjson fastjson 是一個性能很好的 Java 語言實現的 JSON 解析器和生成器&#xff0c;來自阿里巴巴的工程師開發。其主要特點是&#xff1a; ① 快速&#xff1a;fastjson采用獨創的算法&#xff0c;將parse的速度提升到極致&#xff0c;超過所有基于Java的jso…

jQuery Ajax POST方法

Sends an asynchronous http POST request to load data from the server. Its general form is:發送異步http POST請求以從服務器加載數據。 其一般形式為&#xff1a; jQuery.post( url [, data ] [, success ] [, dataType ] )url : is the only mandatory parameter. This…

spss23出現數據消失_改善23億人口健康數據的可視化

spss23出現數據消失District Health Information Software, or DHIS2, is one of the most important sources of health data in low- and middle-income countries (LMICs). Used by 72 different LMIC governments, DHIS2 is a web-based open-source platform that is used…

01-hibernate注解:類級別注解,@Entity,@Table,@Embeddable

Entity Entity:映射實體類 Entity(name"tableName") name:可選&#xff0c;對應數據庫中一個表&#xff0c;若表名與實體類名相同&#xff0c;則可以省略。 注意&#xff1a;使用Entity時候必須指定實體類的主鍵屬性。 第一步&#xff1a;建立實體類&#xff1a; 分別…

leetcode 1707. 與數組中元素的最大異或值

題目 給你一個由非負整數組成的數組 nums 。另有一個查詢數組 queries &#xff0c;其中 queries[i] [xi, mi] 。 第 i 個查詢的答案是 xi 和任何 nums 數組中不超過 mi 的元素按位異或&#xff08;XOR&#xff09;得到的最大值。換句話說&#xff0c;答案是 max(nums[j] XO…

MySQL基礎入門學習【2】數據類型

數據類型&#xff1a;指列、存儲過程參數、表達式和局部變量的數據特征&#xff0c;它決定了數據的存儲格式&#xff0c;代表了不同的信息類型 &#xff08;1&#xff09; 整型(按存儲范圍分類)&#xff1a;TINYINT&#xff08;1字節&#xff09; SAMLLINT&#xff08;2字節&am…

昆西·拉森的凈資產是多少?

People ask me how much I get paid all the time. It comes up on podcast interviews, Quora questions, and face-to-face discussions.人們問我&#xff0c;我一直得到多少報酬。 它來自播客訪談&#xff0c;Quora問題和面對面的討論。 And people search this question a…

COVID-19研究助理

These days scientists, researchers, doctors, and medical professionals face challenges to develop answers to their high priority scientific questions.如今&#xff0c;科學家&#xff0c;研究人員&#xff0c;醫生和醫學專家面臨著挑戰&#xff0c;無法為其高度優先…

Node.js umei圖片批量下載Node.js爬蟲1.00

這個爬蟲在abaike爬蟲的基礎上改改圖片路徑和下一頁路徑就出來了&#xff0c;代碼如下&#xff1a; // // umei圖片批量下載Node.js爬蟲1.00 // 2017年11月13日 //// 內置http模塊 var httprequire("http");// 內置文件處理模塊&#xff0c;用于創建目錄和圖片文件 v…

交通銀行信息技術管理部副總經理張漫麗:交通銀行“大數據+人工智能”應用研究...

文 | 交通銀行信息技術管理部副總經理張漫麗 大數據隱含著巨大的社會、經濟、科研價值&#xff0c;已引起了各行各業的高度重視。如果能通過人工智能技術有效地組織和使用大數據&#xff0c;將對社會經濟和科學研究發展產生巨大的推動作用&#xff0c;同時也孕育著前所未有的機…

安軟件一勞永逸_如何克服一勞永逸地公開演講的恐懼

安軟件一勞永逸If you’re like most people, the idea of public speaking terrifies you (it terrifies me too). So how do you get over those jitters, get up on stage, and give an amazing talk? First, a disclaimer: this article is purely about your stage prese…

Go語言實戰 : API服務器 (8) 中間件

為什么需要中間件 我們可能需要對每個請求/返回做一些特定的操作&#xff0c;比如 記錄請求的 log 信息在返回中插入一個 Header部分接口進行鑒權 這些都需要一個統一的入口。這個功能可以通過引入 middleware 中間件來解決。Go 的 net/http 設計的一大特點是特別容易構建中間…

缺失值和異常值的識別與處理_識別異常值-第一部分

缺失值和異常值的識別與處理&#x1f4c8;Python金融系列 (&#x1f4c8;Python for finance series) Warning: There is no magical formula or Holy Grail here, though a new world might open the door for you.警告 &#xff1a; 這里沒有神奇的配方或圣杯&#xff0c;盡管…

SQL Server 常用分頁SQL

今天無聊和朋友討論分頁&#xff0c;發現網上好多都是錯的。網上經常查到的那個Top Not in 或者Max 大部分都不實用&#xff0c;很多都忽略了Order和性能問題。為此上網查了查&#xff0c;順帶把2000和2012版本的也補上了。 先說說網上常見SQL的錯誤或者說局限問題 12345select…

Word中摘要和正文同時分欄后,正文跑到下一頁,怎么辦?或Word分欄后第一頁明明有空位后面的文字卻自動跳到第二頁了,怎么辦?...

問題1&#xff1a;Word中摘要和正文同時分欄后&#xff0c;正文跑到下一頁&#xff0c;怎么辦&#xff1f;或Word分欄后第一頁明明有空位后面的文字卻自動跳到第二頁了&#xff0c;怎么辦&#xff1f; 答&#xff1a;在word2010中&#xff0c;菜單欄中最左側選“文件”->“選…

leetcode 664. 奇怪的打印機(dp)

題目 有臺奇怪的打印機有以下兩個特殊要求&#xff1a; 打印機每次只能打印由 同一個字符 組成的序列。 每次可以在任意起始和結束位置打印新字符&#xff0c;并且會覆蓋掉原來已有的字符。 給你一個字符串 s &#xff0c;你的任務是計算這個打印機打印它需要的最少打印次數。…

SQL數據類型說明和MySQL語法示例

SQL數據類型 (SQL Data Types) Each column in a database table is required to have a name and a data type. 數據庫表中的每一列都必須具有名稱和數據類型。 An SQL developer must decide what type of data that will be stored inside each column when creating a tab…

PHP7.2 redis

為什么80%的碼農都做不了架構師&#xff1f;>>> PHP7.2 的redis安裝方法&#xff1a; 順便說一下PHP7.2的安裝&#xff1a; wget http://cn2.php.net/distributions/php-7.2.4.tar.gz tar -zxvf php-7.2.4.tar.gz cd php-7.2.4./configure --prefix/usr/local/php…

leetcode 1787. 使所有區間的異或結果為零

題目 給你一個整數數組 nums??? 和一個整數 k????? 。區間 [left, right]&#xff08;left < right&#xff09;的 異或結果 是對下標位于 left 和 right&#xff08;包括 left 和 right &#xff09;之間所有元素進行 XOR 運算的結果&#xff1a;nums[left] XOR n…