Champion of hdu-2094

Source: Internet
Author: User

Question:

Champion
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 4716 Accepted Submission (s): 2274
Problem Description
There are a group of people playing a table tennis competition, and they can play at most one game between each other.
The rules of the game are as follows:
If A beat B, B beat C again, and A and C do not compete, then it is determined that A will defeat C.
If A beat B, B beat C, and C beat A, then A, B, and C won't be the champion.
According to this rule, you may be able to determine the champion without repeating the contest. Your task is to face a group of contestants. After several battles, determine whether they have actually won the championship.
 

Input
The input contains some contestant groups. Each contestant group starts with an integer n (n <1000) and is followed by the result of the n-to-n match, the results of the competition are represented by a pair of contestants (separated by a space). The former prevails over the latter. If n is 0, the input ends.
 

Output
For each contestant group, if you determine that you have won the championship, "Yes" is output in one row; otherwise, "No" is output in one row ".
 

Sample Input
3
Alice Bob
Smith John
Alice Smith
5
A c
C d
D e
B e
A d
0
 

Sample Output
Yes
No

// Train of thought: record all the names that have appeared, and check whether the last one has been lost. If not, t ++ determines whether t = 1?
// Stl knowledge connection http://blog.csdn.net/xiongheqiang/article/details/7769633

AC code:
[Cpp]
# Include <iostream>
Using namespace std;
# Include <string>
# Include <map>
# Include <set> // when the container inputs two identical elements, only one
Int main ()
{
Int n, I;
Set <string> name; // put all existing names in the set container.
Set <string>: iterator r; // set pointer
Map <string, string> com;
While (cin> n, n! = 0)
{
String a, B;
Name. clear ();
Com. clear ();
For (I = 0; I <n; I ++)
{
Cin> a> B;
Name. insert ();
Name. insert (B );
Com [B] = a; // mark B lost to
}
Int t = 0; // t indicates the number of students not lost.
For (r = name. begin (); r! = Name. end (); r ++)
If (! Com [* r]. length () // If com [B] is not input, the length is 0.
{
T ++;
If (t> 1)
Break;
}
Puts (t = 1? "Yes": "No ");
}
Return 0;
}
Author: xiongheqiang

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.