记录编号 |
152247 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2008]玩具取名 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.338 s |
提交时间 |
2015-03-13 21:00:03 |
内存使用 |
0.45 MiB |
显示代码纯文本
/***********************************************************************/
/**********************By Asm.Def-Wu Jiaxin*****************************/
/***********************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std;
FILE *in, *out;
#define SetFile(x) ( in = fopen(#x".in", "r"), out = fopen(#x".out", "w") )
#define SetIO(i, o) ( in = i, out = o )
#define getc() fgetc(in)
template<class T>inline void getd(T &x){
char ch = getc();bool neg = false;
while(!isdigit(ch) && ch != '-')ch = getc();
if(ch == '-')ch = getc(), neg = true;
x = ch - '0';
while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
if(neg)x = -x;
}
/***********************************************************************/
const char CH[] = "WING";
const int maxn = 202;
int str[maxn], len;
bool trans[4][4][4], comp[4][maxn][maxn];
#define For(i, j, k) for(i = j;i < k;++i)
#define id(ch) ((ch < 'N') ? (ch == 'I' ? 1 : 3) : (ch == 'W' ? 0 : 2))
inline void init(){
int cnt[4], a, b, i;
for(i = 0;i < 4;++i)getd(cnt[i]);
for(i = 0;i < 4;++i)while(cnt[i]--){
while(!isalpha(a = fgetc(in)));a = id(a);
b = fgetc(in);b = id(b);
trans[a][b][i] = true;
}
i = 0;while(!isalpha(a = fgetc(in)));str[i++] = id(a);
while(isalpha(a = fgetc(in)))str[i++] = id(a);
len = i;
}
inline void work(){
int i, j, k, a, b, c;
For(i,0,len)comp[str[i]][i][i+1] = true;
For(i,2,len+1)For(j,0,len+1-i)For(c,0,4)
For(k,j+1,i+j){
if(comp[c][j][i+j])break;
For(a,0,4)if(comp[a][j][k])For(b,0,4)if(comp[b][k][i+j])
if(trans[a][b][c])comp[c][j][i+j] = true;
}
bool ans = false;
For(a,0,4)if(comp[a][0][len])fputc(CH[a], out), ans = true;
if(!ans)fprintf(out, "The name is wrong!");
fputc('\n', out);
}
int main(){
#ifdef DEBUG
SetIO(fopen("test.txt", "r"), stdout);
#elif !defined ONLINE_JUDGE
SetFile(name);
#else
SetIO(stdin, stdout);
#endif
init();
work();
#ifdef DEBUG
printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}