Gym
来源:互联网 发布:软件项目外包 编辑:程序博客网 时间:2024/06/05 06:48
Gym - 100814J Game
题意是给一个26x26的字母表,再给一个字符串,字符串可以从左开始读,也可以从右开始读,按读的顺序,两个字母一组,ab就相当于一行二列,用字母表对应得字母来代替ab,最后如果有一个多的字母就直接保留。Salah和Marzo一起玩游戏,轮流将字符串按字母表转换,Salah是先手,最后只剩一个字母时游戏结束,如果是元音字母,则Salah赢,否则Marzo赢。
直接DFS,每次记录当前操作者是Salah还是Marzo,因为每次都是走最优的,所有如果Salah在操作,则只要她的下一步(从左开始,或从右开始)有结果是元音的,就返回1;同理,Marzo的下一步中,如果有结果不是元音的,就返回0。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>#include <bitset>#define INF 0x3f3f3f3f#define eps 1e-6#define PI 3.1415926#define mod 1000000009#define base 2333using namespace std;typedef long long LL;const int maxn = 1e4 + 10;const int maxx = 1e3 + 10;inline void splay(int &v) { v=0;char c=0;int p=1; while(c<'0' || c >'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p;}int t;char mm[30][30], str[maxn];int dfs(char *ss, int tt) { char xx[maxn], yy[maxn]; int c1 = 0, c2 = 0, len = strlen(ss); if(len == 1) { if(ss[0] == 'a' || ss[0] == 'e' || ss[0] =='i' || ss[0] == 'o' || ss[0] == 'u') return 1; return 0; } else if(len > 1) { for(int i = 0; i+1 < len; i+=2) xx[c1++] = mm[ss[i]-'a'][ss[i+1]-'a']; if(len&1) xx[c1++] = ss[len-1], yy[c2++] = ss[0]; for(int i = len&1; i+1 < len; i+=2) yy[c2++] = mm[ss[i]-'a'][ss[i+1]-'a']; xx[c1] = '\0', yy[c2] = '\0'; int l = dfs(xx, tt^1); int r = dfs(yy, tt^1); if(tt == 1) { if(l || r) return 1; else return 0; } else { if(!l || !r) return 0; else return 1; } }}void solve() { splay(t); while(t--) { for(int i = 0; i < 26; i++) scanf("%s", mm[i]); scanf("%s", str); int flag = dfs(str, 1); if(flag) printf("Salah\n"); else printf("Marzo\n"); }}int main() { //srand(time(NULL)); //freopen("kingdom.in","r",stdin); //freopen("kingdom.out","w",stdout); solve();}