前言:
美哉美哉,这题难度一般,五分钟秒切了
----------------------------- 分界线
题目理解 我们有:
一根脊椎骨,长度固定为 N 根肋骨,第 i 根肋骨长度要求为 a[i],且它的第 b [i]个字符必须等于脊椎骨的第 i 个字符 有 M 个候选字符串(长度≤10互不相同),所有 N+1 根骨头的字符串必须从中选择(可重复) 对每个候选字符串s[j] ,问:是否存在一种选择方式,使得脊椎骨上写 s[j] ,且满足所有条件,每根肋骨只与脊椎骨的一个字符有关,与其他肋骨无关。 所以问题可以分解为:对每根肋骨 i,判断是否存在一个候选字符串,长度 = a[i] ,且第 b[i] 个字符 = 脊椎骨的第 i 个字符。
可得代码
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+10;
int n;
int a[11],b[11];
string s[M];
int f[11][27];
int main(){
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i];
}
int m;
cin >> m;
for(int i=1;i<=m;i++) cin >> s[i];
for(int i=1;i<=m;i++){
string x=s[i];
int len=x.length();
for(int j=1;j<=n;j++){
if(a[j]==len){
int idx=b[j]-1;
char c=x[idx];
f[j][c-'a']=true;
}
}
}
for(int i=1;i<=m;i++){
string x=s[i];
if(x.length()!=n){
cout << "No" << '\n';
continue;
}
bool k=true;
for(int j=1;j<=n;j++){
char c=x[j-1];
if(!f[j][c-'a']){
k=false;
break;
}
}
if(k) cout << "Yes" << '\n';
else cout << "No" << '\n';
}
return 作者牛福克拉斯;
}
完结撒花,管理员求过