Each person has a frist name and a last name! Choose from the name of each person
First name or last name is the ID of this person! Sort the numbers to get each person
Final Order! Can the sequence in the comparison be consistent with the sequence of the given output!
1 # include <iostream> 2 # include <cstring> 3 # include <cstdio> 4 # include <string> 5 # include <map> 6 # include <algorithm> 7 # define n 100005 8 using namespace STD; 9 10 int P [N]; 11 string name [2 * n]; 12 Map <string, int> MP; // map the name of each person to the nth person 13 14 15 int main () {16 int N; 17 int CNT = 0; 18 CIN> N; 19 For (INT I = 1; I <= N; ++ I) {20 CIN> name [CNT ++]> name [CNT ++]; 21 MP. insert (make_pair (name [cnt-2], I); 22 MP. insert (make_pair (name [cnt-1], I); 23} 24 for (INT I = 1; I <= N; ++ I) // The sorting sequence of each person is 25 CIN> P [I]; 26 sort (name, name + CNT); // sorting 27 int K = 1; 28 For (INT I = 0; I <CNT; ++ I) // greedy 29 If (MP [name [I] = P [k]) {30 + + k; 31 if (k> N) break; 32} 33 If (k> N) cout <"yes"; 34 else cout <"no "; 35 cout <Endl; 36 return 0; 37}View code
Codeforces C. Design Tutorial: Make it Nondeterministic