Question: There are a group of people, playing table tennis games, 22 catch to kill, every two people to 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.
Examples:
3 Alice Bob Smith John Alice Smith 5 a C c D d e b e a D 0 analysis: The second column is the loser ... Directly find the person who has not lost a few, if it is the first to produce a champion ... Other bloggers have some doubts about the problem ... Say: A beats b,b to defeat C; At the same time: D beats E, E defeats F, F beats D. The latter is a cycle, it is impossible to determine that a defeated D, E, f ... I think there's some truth in what this great God says ... I didn't think so much ... So let's do it first ... Level Limited ...
#include <iostream>
#include <cstdio>
#include <string>
#include <set>
using namespace std;
int main () {
int q;
Set<string> all;
Set<string> lose;
while (scanf ("%d", &q)!=eof && q) {
string A, B;
while (q--) {
cin>>a>>b;
All.insert (a);
All.insert (b);
Lose.insert (b);
}
if (All.size ()-lose.size () = = 1) cout<< "Yes" <<endl;
else cout<< "No" <<endl;
All.clear ();
Lose.clear ();
}
return 0;
}