F. Elementary! time
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output “YES” or “NO”.
Examples
GENIUS
YES
DOCTOR
NO
IRENE
YES
MARY
NO
SMARTPHONE
NO
REVOLVER
YES
HOLMES
NO
WATSON
YES
题解:愚人节专场还是一如既往的有意思,从题目的另一个解释——元素能猜出和什么元素有关,最后发现如果串能拆成若干化学元素则为YES,因此只好打表,再用dfs爆搜即可。
#include<bits/stdc++.h>
using namespace std;
char s[300][10]={"H","HE","LI","Be","B","C","N","O","F","NE","NA","MG","AL","SI","P","S","CL","AR","K","CA","SC","TI","V","CR","MN","FE","CO","NI","CU","ZN","GA","GE","AS","SE","BR","KR","RB","SR","Y","ZR","NB","MO","TC","RU","RH","PD","AG","CD","IN","SN","SB","TE","I","XE","CS","BA","LA","CE","PR","ND","PM","SM","EU","GD","TB","DY","HO","ER","TM","YB","LU","HF","TA","W","RE","OS","IR","PT","AU","HG","TL","PB","BI","PO","AT","RN","FR","RA","AC","TH","PA","U","NP","PU","AM","CM","BK","CF","ES","FM","MD","NO","LR","RF","DB","SG","BH","HS","MT","DS","RG","CN","NH","FL","MC","LV","TS","OG"};
int sum=118;
string res;
bool ok=false;
int l;
void dfs(int x)
{
if(l==x)
{
ok=true;
return;
}
for(int i=0;i<sum;i++)
{
int p=strlen(s[i]);
if(p+x>l) continue;
bool vst=true;
for(int j=0;j<p;j++)
{
if(s[i][j]!=res[x+j])
{
vst=false;
break;
}
}
if(vst)
{
dfs(x+p);
if(ok) return;
}
}
}
int main()
{
cin>>res;
l=res.size();
dfs(0);
if(ok) cout<<"YES";
else cout<<"NO";
return 0;
}