A
思路很简单,就是找NP V NP,但是感觉题解们的代码都不是很方便(
其实就是这么几个步骤:
- 找唯一动词(即4,只能做动词)的个数
- 如果有超过一个(
) 那么显然不存在
- 如果只有一个,那么只要看这个动词前面和最后一个是不是N就行
- 如果一个都没有,就去枚举所有可以当V的(即&4后非零),然后看前面一个和最后一个是不是N就行
- 如果有超过一个(
注释应该挺详细的吧(xd
#include<map> #include<set> #include<cmath> #include<queue> #include<bitset> #include<vector> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define rep(i,a,b) for(int i = (a);i <= (b);++i) #define per(i,a,b) for(int i = (a);i >= (b);--i) #define mkp std::make_pair typedef long long ll; typedef unsigned long long ull; using std::string;using std::cin;using std::cout; inline bool cmp(int x,int y){return x < y;} /* -fsanitize=undefined */ const int N = 1e7+9; const int inf = 1e9+9; const double eps = 1e-7; int _,ab[30],len,cntV; char ch[2*N]; bool haveN[2*N],haveV[2*N],flag; int main(){ std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef LOCAL // -DLOCAL freopen("in.in", "r", stdin); #endif cin >> _; while(_--){ flag = false; rep(i,0,len+1) haveN[i] = haveV[i] = false , ch[i] = ' '; cntV = 0; rep(i,1,26) cin >> ab[i]; cin >> ch+1; len = strlen(ch+1); if(!(ab[ ch[len]-'a'+1 ] & 2)){ // 必要条件 cout << "No\n"; continue; } rep(i,1,len){ // 实际上真正必要的只有第三行,前面两行只是用来精简代码的 if(ab[ ch[i]-'a'+1 ] & 2) haveN[i] = true; if(ab[ ch[i]-'a'+1 ] & 4) haveV[i] = true; if(ab[ ch[i]-'a'+1 ] == 4) ++cntV; // 计算唯一动词数量 } // cout << "❶\n"; // rep(i,1,len) cout << haveN[i] << " "; // cout << "\n"; // rep(i,1,len) cout << haveV[i] << " "; // cout << "\n"; if(cntV > 1){ // 唯一动词不唯一时必定不存在 // cout << "❷\n"; cout << "No\n"; continue; } else { rep(i,2,len-1){ if( haveV[i] && (cntV == 0) || // 不存在唯一动词 ab[ ch[i]-'a'+1 ] == 4 && (cntV == 1) // 存在唯一动词 ) if(haveN[i-1]){ cout << "Yes\n"; flag = true; break; } } if(flag) continue; // cout << "❸\n"; cout << "No\n"; } } return 0; }