The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners

    科技2022-07-11  94

    The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners

    题目链接

    Harbin, whose name was originally a Manchu word meaning “a place for drying fishing nets”, grew from a small rural settlement on the Songhua River to become one of the largest cities in Northeast China. Founded in 1898 with the coming of the Chinese Eastern Railway, the city first prospered as a region inhabited by an overwhelming majority of the immigrants from the Russian Empire. Now, Harbin is the capital of Heilongjiang province and the largest city in the northeastern region of the People’s Republic of China. It serves as a key political, economic, scientific, cultural, and communications hub in Northeast China, as well as an important industrial base of the nation. This year, a CCPC regional contest is going to be held in this wonderful city, hosted by Northeast Forestry University. To ensure the contest will be a success and enjoyed by programmers around the country, preparations for the event are well underway months before the contest. You are the leader of a student volunteer group in charge of making banners to decorate the campus during the event. Unfortunately, your group made a mistake and misprinted one of the banners. To be precise, the word “harbin” is missing in that banner. Because you don’t have time to reprint it, the only way to fix it is to cut letters from some used old banners and paste them onto the misprinted banner. You have exactly six banners, and for some reason, you must cut exactly one letter from each banner. Then, you can arrange and paste the six letters onto the misprinted banner and try to make the missing word “harbin”. However, before you start cutting, you decide to write a program to see if this is possible at all.

    Input

    The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤50000), the number of cases. For each case, the input contains six lines. Each line contains a non-empty string consisting only of lowercase English letters, describing the letters on one of the old banners. The total length of all strings in all cases doesn’t exceed 2e6.

    Output

    For each case, print the string “Yes” (without quotes) if it is possible to make the word “harbin”, otherwise print the string “No” (without quotes).

    Example

    input

    2 welcome toparticipate inthe ccpccontest inharbin inoctober harvest belong ninja reset amazing intriguing

    output

    No Yes

    这题直接暴力就行,求一个 “harbin” 的全排列,找每个字符串是否有该字符即可,但是一定要预处理每个字符串存在的字符,而且不能用 m a p map map,习惯 STL 的我哭了, m a p map map 会 T,unordered 我没试过,估计也差不多,改成数组就过了,DFS 的话也可以,不过 DFS 比较难写,复杂度是一样的,好像还有人用二分图匹配的,那感觉就想复杂了😂,AC代码如下:

    #include<bits/stdc++.h> using namespace std; typedef long long ll; int t; string target,s[6]; int main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin>>t; while(t--){ target="abhinr"; int flag=0; int m[6][26]; memset(m,0,sizeof(m)); for(int i=0;i<6;i++){ cin>>s[i]; for(auto j:s[i]) m[i][j-'a']=1; } do{ int num=0; for(int i=0;i<6;i++){ if(m[i][target[i]-'a']) num++; } if(num==6){ flag=1; break; } }while(next_permutation(target.begin(),target.end())); if(flag) cout<<"Yes\n"; else cout<<"No\n"; } return 0; }
    Processed: 0.035, SQL: 8