(Hdu step 5.2.6) determine the tournament position (the number of points for which the degree is 0)

Source: Internet
Author: User

Topic:

Determine the position of the match
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 338 Accepted Submission (s): 181
Problem description has N teams (1<=n<=500), numbered three-in-one, .... , N to play, after the game, the Referee Committee will be all the teams from the arrival of the ranking, but now the referee committee can not directly get each team's performance, only know the results of each game, that is, P1 win P2, with P1,p2 said, ranked P1 before P2. Now ask you to compile the program to determine the rankings.
Input inputs have several groups, the first behavior in each group is two n (1<=n<=500), M, where n represents the number of troops, and m represents the input data for the M row. In the next M-row data, there are also two integers per line p1,p2 means that the P1 team won the P2 team.
Output
Give a ranking that meets the requirements. There is a space between the queue numbers at the time of the output, and no space after the last.

Other Notes: Qualifying rankings may not be unique, at which point the output is required to be numbered in front of the team; the input data is guaranteed to be correct, i.e. the input data ensures that there must be a qualifying ranking.
Sample Input
4 31 22) 34 3
Sample Output
1 2 4 3
Authorsmallbeer (CML)
SOURCE Hangzhou Electric ACM Training Team Training Tournament (VII)
Recommendlcy



Topic Analysis:

Topological sequences, simple questions. In fact, this problem is attributed to the "topological sequence" problem, because in the re-brush this topic, with a topological sequence can be done

。 There are also various other practices on the Web. But the question is abstracted as "whether the number of points that are judged to be 0 is unique" can be AC. In fact, the condition of being able to produce a championship is: "Only one person has not lost the"---"Only one point in the 0. In this problem, you need to pay attention to the way map is traversed.



The code is as follows:

/* * f.cpp * *  Created on:2015 March 8 *      author:administrator * * #include <iostream> #include <cstdio> #i Nclude <map>using namespace Std;int main () {int n;while (scanf ("%d", &n)!=eof,n) {map<string,int> Indegree;string Str1,str2;int i;for (i = 0; i < n; ++i) {cin >> str1 >> str2;if (indegree.find (str1) = = Indeg Ree.end ()) {INDEGREE[STR1] = 0;} indegree[str2]++;} int cnt = 0;//need to be aware of the way map is traversed map<string,int>::iterator iter;for (iter = Indegree.begin (); ITER! = Indegree.end (); + + ITER) {if (Iter->second = = 0) {cnt++;//cout << iter->first << ":" << iter->second << Endl;} }//cout << CNT << endl;if (cnt = = 1) {//If the number of points with an entry of 0 is 1printf ("yes\n"), the//can produce a championship}else{//if the number of points in 0 is not 1printf ( "no\n");//cannot produce champion}}return 0;}









(Hdu step 5.2.6) determine the tournament position (the number of points for which the degree is 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.