The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners
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;
}
相關文章
- 2020 China Collegiate Programming Contest Qinhuangdao Site
- 2022 China Collegiate Programming Contest (CCPC) Guilin SiteGUI
- 2022 International Collegiate Programming Contest, Jinan SiteNaN
- 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming ContestACM
- 2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite E Hammer to Fall
- 2024 Jiangsu Collegiate Programming Contest
- The 2024 CCPC Shandong Invitational Contest and Provincial Collegiate Programming Contest
- 2015 ACM Syrian Collegiate Programming ContestACM
- 2017 ACM Jordanian Collegiate Programming ContestACM
- The 8th Hebei Collegiate Programming Contest: F - 3 Split
- The 2022 ICPC Polish Collegiate Programming Contest (AMPPZ 2022)
- 2021 Hubei Provincial Collegiate Programming Contest/2021湖北省賽 題解
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)ACM
- 2024年3月20日 VP[The 13th Shandong ICPC Provincial Collegiate Programming Contest]
- E Revenge on My Boss CCPC 2023 Harbin Site 貪心,二分
- Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字串,模擬】...ASTAI字串
- 2024 BUPT Programming Contest F
- Toyota Programming Contest 2024#3(AtCoder Beginner Contest 344)
- Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)
- Toyota Programming Contest 2024#7(AtCoder Beginner Contest 362)
- AISing Programming Contest 2021(AtCoder Beginner Contest 202)AI
- Toyota Programming Contest 2024#11(AtCoder Beginner Contest 379)
- KEYENCE Programming Contest 2024(AtCoder Beginner Contest 374)題解
- UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346)Spring
- 2019-2020 ICPC Southeastern European Regional Programming Contest (SEERC 2019) 補題記錄AST
- 2014 Benelux Algorithm Programming Contest (BAPC 14)UXGo
- The 2022 ICPC Asia Hangzhou Regional Programming Contest
- Hitachi Vantara Programming Contest 2024(AtCoder Beginner Contest 368)題解A~D
- Toyota Programming Contest 2024#11(AtCoder Beginner Contest 379)題解
- North American Invitational Programming Contest 2018
- Hitachi Vantara Programming Contest 2024(AtCoder Beginner Contest 368)F - Dividing GameGAM
- Toyota Programming Contest 2024#11(AtCoder Beginner Contest 379)題解總結
- TOYOTA SYSTEMS Programming Contest 2024(AtCoder Beginner Contest 377) 補題記錄(A-E)
- CF2019 F. Max Plus Min Plus Size
- 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)
- 2022 Benelux Algorithm Programming Contest (BAPC 22) A 、I、J、LUXGo
- F. Microcycle
- F. Bomb