POJ 3660 & amp; NYOJ 211 Cow Contest (Floyd transfer closure), poj3660

Source: Internet
Author: User

POJ 3660 & NYOJ 211 Cow Contest (Floyd transfer closure), poj3660

Link: click here

There is an nheaded ox, and each ox has a unique and different level of competence. then, the two of them will play M games and give you the results of the M games. the question is, how many of you can determine your ranking? If a WINS B and B wins c, a wins c. and if you already know a wins the number of cattle + than a powerful number of cattle = N-1, then a ranking can certainly be launched.

Idea: Indicates data tangle ~~, After suddenly understanding it, I thought that the number of defeated instances and the number of defeated instances exactly equal to n-1 can be determined. Otherwise, they cannot be determined.

Code:

# Include <stdio. h> // (passing the closure floyed algorithm) # include <string. h >#include <iostream >#include <algorithm> using namespace std; const int maxn = 110; int map [maxn] [maxn]; int n, m; int main () {int I, j, k, x, y, cnt1, cnt2; while (~ Scanf ("% d", & n, & m), n + m) {memset (map, 0, sizeof (map); while (m --) {scanf ("% d", & x, & y); map [x] [y] = 1 ;}for (k = 1; k <= n; k ++) {for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) {if (map [I] [k] & map [k] [j]) {// printf ("$ % d $", I, k, k, j); map [I] [j] = 1; // assigned link }}} int count = 0; for (I = 1; I <= n; I ++) {cnt1 = 0; cnt2 = 0; for (j = 1; j <= n; j ++) {// if (I = j) continue; // if (map [I] [j] = 0 & map [j] [I] = 0) break; if (map [I] [j]) {// printf ("# I = % d j = % d #", I, j); cnt1 ++ ;} if (map [j] [I]) {// printf ("# j = % d I = % d #", j, I); cnt2 ++ ;}} if (cnt1 + cnt2 = (n-1) // The number of defeated instances plus the number of defeated instances exactly equal to n-1 {count ++ ;}} printf ("% d \ n", count);} return 0 ;}


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.