HDU2094 (generation of Champions)

Source: Internet
Author: User

HDU2094 (generation of Champions)

Just in case, the original title and links are attached to the end of the text. So first the topic analysis:

"A Word test instructions"

Deduce the analysis champion based on the given existing match results. (This describes ...) I suggest or read the question, not long.

"Problem Analysis"

The data given is the ♂ between each of the two players, so thought is a simple chain list, and then feel is and check set, and then found not science. So a special science of ordinary simple rough cute method.
Before I say the method, I would like to spit a few words. The problem seems to be not rigorous enough. If there is a group of a>b;b>c;c>a;d>e in the data, it will be divided into two unrelated combinations. In this case, I feel that I should be able to output no (two groups did not have a game before, there is no way to know if D can beat ABC to become the champion). And actually the output is yes. So........ It doesn't feel scientific.

"Algorithmic Flow"

Column list, Cypriot staff:
The fact is that all the names are listed, have never won the fall, won and lost the fall. The rest if there is only one that is the champion, if more than one is not.
Simple optimization:
Instead of listing everyone's name and filtering out the winning one, it's better to just give the winning list. Then we need two tables, one for the winner (as long as you win), one for the loser (as long as you lose). Then take each of the winners in the loser, and if you find it, you can drop it. The last thing left is a super big winner. Of course, in order to go heavy, we choose to use the set set in the STL container to handle the de-weight.
Stl:set (Std::set):

    • Initialize to create:set<string> loserlist;
    • Empty element: Loserlist.clear ();
    • Insert in collection: Loserlist.insert (loser);
    • Find whether the collection exists: Loserlist.find (*winneriter) ==loserlist.end ()//does not exist

These things are listed for those who have not yet contacted the STL reference
If you've never been in touch with Std::set, see http://www.cplusplus.com/reference/set/set/.
If you have never contacted STL, please review the CPP.

#include <iostream>#include<string>#include<algorithm>#include<Set>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#defineEach (i,n) (int i=1;i<= (n); ++i)using namespacestd;intMain () {Set<string>winnerlist; Set<string>loserlist; stringWinner,loser; intdatacount, Flag;  while(SCANF ("%d", &datacount)! =EOF) {        if(Datacount = =0) Break;        Winnerlist.clear ();        Loserlist.clear ();  while(datacount--) {cin>>winner>>loser;            Winnerlist.insert (winner);        Loserlist.insert (loser); } Flag=0; Set<string>::iterator winneriter=Winnerlist.begin ();  for(; Winneriter!=winnerlist.end (); winneriter++) {            if(Loserlist.find (*winneriter) = =Loserlist.end ()) {                //cout<< "[" <<*winnerIter<<endl; who would have expected to export the winner ... ++Flag; //Break ;            }        }        if(Flag = =1) {cout<<"Yes"<<Endl; } Else{cout<<"No"<<Endl; }    }} /*TestData (in) 3Alice bobsmith Johnalice smith5a CC DD EB expert d0testdata (out) YesNo*/

Title Link: (HDU 2094) Produce champion

Topic Properties: Brain Teasers (there are said to be and check the set, there are topological sort of, I just started to think it is a single-linked list, well, tube him?). ), STL application exercise (can be applied as a practice bar ... )
Related topics: 1342, 1361, 1370, 1506, 1577, 1597, 1702, 1716, 1727 (not all brain teasers)
Original title:
"Desc" There is a group of people, playing table tennis game, 22 catch to kill, every two people play a maximum of a game.
The rules of the game are as follows:
If a defeated B,b and defeated C, and A and C did not play, then it is decided that a must be able to defeat C.
If a defeated B,b and defeated C, and C defeated A, then a, B, C Three will not be the champion.
According to this rule, there is no need to cycle a contest, perhaps to determine the championship. Your task is to face a group of contestants, after a number of killings, to determine whether it has actually produced a championship.
The "in" input contains a number of contestants, each of which starts with an integer n (n<1000) followed by N against the competitor, and the result is given by a pair of player names (one space between them), the former defeating the latter. If n is 0, it indicates the end of the input.
The "Out" input contains a number of contestants, each of which starts with an integer n (n<1000) followed by N against the competitor, and the result is shown by a pair of player names (one space in intervals), the former defeating the latter. If n is 0, it indicates the end of the input.
"Sampin/out" See comments below the code.

HDU2094 (generation of Champions)

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.