AcWing 3746. Cow's Academic Circle II (Thinking Questions)

[Title Description]
Bessie is applying for graduate school in computer science and has received an interview call from a prestigious computer science laboratory.
However, to avoid offending anyone, Bessie deliberately identified the lab's NN firstRelative seniority of N existing members.
No two lab members have the same seniority, but determining how senior they are can be tricky.
To do this, Bessie will conduct a survey of the lab's publications.
Each publication contains a list of authors for allNNA permutation of N lab members. The list is sorted in descending order
of each lab member's contribution to this article. If multiple researchers contributed equally, they arelexicographically. Since more senior lab members have more management responsibilities, more senior researchers never make more contributions than less senior researchers. For example, in a laboratory consisting of a junior student Elsie, a senior professor Mildred, and a very senior professor Dean, there may exist a paper Elsie-Mildred-Dean if they make unequal Contributed (that is, Elsie contributed more than Mildred, and Mildred more than Dean). However, it is also possible that a paper Elsie-Dean-Mildred exists if Mildred and Dean contribute equally and Elsie contributes more. KKfor a given lab




K publications, for each pair of researchers in the lab, help Bessie determine, if possible, which of them is more senior.

[Input format]
The first line of input contains two integers KKK andNNN. _
The second line containsNNA space-separated string of N space-separated names for the lab members. Each string consists of lowercase letters and contains at most10 1010 characters.
The followingKKK lines, each line containsNNN space-separated string representing a list of authors for a publication.

【Output format】
Output NNN lines, each lineNNN characters. SectioniiIn row i , for all j ≠ ij≠ij=i , when it can be determined that theiiMember i is more than jjWhen the seniority of j members is higher, the characterjjj is1 11 , when it can be determined thatiiMember i is more than jjCharacter jj when j members have junior seniorityj is0 00 when it cannot be determined by the given publication?.
SectionIIcharacterii of row ii should beBbecause that is Bessie's favorite letter.

【Data range】
1 ≤ N , K ≤ 100 1≤N, K≤1001N,K100

【Input example 1】

1 3
dean elsie mildred
elsie mildred dean

【Output sample 1】

B11
0B?
0?B

[Explanation of Example 1]
In this example, a single paper elsie-mildred-dean does not provide enough information to judge whether Elsie is more senior or less senior than Mildred.
However, we can infer that Dean must be more senior than these two researchers, so the seniority rankings are both Elsie<Mildred<Dean and Mildred<Elsie<Dean are possible.

【Input example 2】

2 3
elsie mildred dean
elsie mildred dean
elsie dean mildred

【Output sample 2】

B00
1B0
11B

[Explanation of Example 2]
In this example, the only seniority ranking that can be consistent with the two papers is Elsie<Mildred<Dean, because based on the information provided by the first sample, the second paper can help We deduce that Mildred has more seniority than Elsie.

【analyze】


Hotel aaa andbbThe qualifications of b are respectivelyE a E_aEaE b E_bEb, the contributions are respectively C a C_aCaand C b C_bCb, if it can be determined that E a < E b E_a<E_bEa<Eb, it must satisfy C a > C b C_a>C_bCa>Cb, that is, in the paper aaa 's name appears inbbin front of b , andaaa tobbThe names between b are not all in ascending lexicographical order.

So we can iterate over each name of the paper iii , iniiFind the name jjof the first lexicographical descending order after ij , thenjjj and all subsequent seniority are strictly higher thaniii


【Code】

#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_map>
using namespace std;

const int N = 110;
int g[N][N];//g[a][b] = 1表示a的资历比b高
int n, m;
unordered_map<string, int> id;

int main()
{
    
    
    cin >> m >> n;
    for (int i = 0; i < n; i++)
    {
    
    
        string s;
        cin >> s;
        id[s] = i;
    }
    string name[N];
    while (m--)
    {
    
    
        for (int i = 0; i < n; i++) cin >> name[i];
        for (int i = 0; i < n; i++)
        {
    
    
            int j = i + 1;
            while (j < n && name[j] > name[j - 1]) j++;//找到第一个降序的名字
            while (j < n)//j之后的所有人资历都严格比i高
            {
    
    
                int a = id[name[i]], b = id[name[j]];
                g[b][a] = 1;
                j++;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
    
    
        for (int j = 0; j < n; j++)
            if (i == j) cout << 'B';
            else if (!g[i][j] && !g[j][i]) cout << '?';
            else cout << g[i][j];
        cout << endl;
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/m0_51755720/article/details/129625195