Poj 3360 H-cow contest

Source: Internet
Author: User
Tags rounds

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 conducting CTED in several head-to-head rounds, each between two cows. If cowAHas a greater skill level than cowB(1 ≤AN; 1 ≤BN;A=B), Then cowAWill always beat cowB.

Farmer John is trying to rank the cows by skill level. Given a list the resultsM(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 contradic.pdf.

Input

* Line 1: two space-separated integers:NAndM
* 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:AAndB

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined

Sample Input

 
5 54 34 23 21 22 5

Sample output

 
2

Question: $ Floyd $ if the winner of the algorithm is added with the sum of $ n-1 $, it is the person who can determine the position.

Code:

# Include <stdio. h> # include <string. h> # include <iostream> # include <math. h> using namespace STD; int n, m; int MP [110] [110]; void Floyd () {for (int K = 1; k <= N; k ++) {for (INT I = 1; I <= N; I ++) {If (MP [I] [k]) for (Int J = 1; j <= N; j ++) {If (MP [k] [J] = 1 & MP [I] [k] = 1) {MP [I] [J] = 1; MP [J] [I] =-1 ;} else if (MP [k] [J] =-1 & MP [I] [k] =-1) {MP [I] [J] =-1; MP [J] [I] = 1;} else continue ;}}} int main () {memset (MP, 0, sizeof (MP )); scanf ("% d", & N, & M); For (INT I = 1; I <= m; I ++) {int A, B; scanf ("% d", & A, & B); MP [a] [B] = 1; MP [B] [a] =-1 ;} floyd (); int ans = 0; For (INT I = 1; I <= N; I ++) {int sum = 0; For (Int J = 1; j <= N; j ++) if (MP [I] [J]) sum ++; If (sum = n-1) ans ++ ;} printf ("% d \ n", ANS); Return 0 ;}

Poj 3360 H-cow contest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.