小明经常玩 LOL 游戏上瘾,一次他想挑战K大师,不料K大师说: “我们先来玩个空格填字母的游戏,要是你不能赢我,就再别玩LOL了”。
K大师在纸上画了一行n个格子,要小明和他交替往其中填入字母。
并且:
- 轮到某人填的时候,只能在某个空格中填入L或O
- 谁先让字母组成了“LOL”的字样,谁获胜。
- 如果所有格子都填满了,仍无法组成LOL,则平局。
小明试验了几次都输了,他很惭愧,希望你能用计算机帮他解开这个谜。
本题的输入格式为: 第一行,数字n(n<10),表示下面有n个初始局面。 接下来,n行,每行一个串(长度<20),表示开始的局面。 比如:“******”, 表示有6个空格。 “L****”, 表示左边是一个字母L,它的右边是4个空格。
要求输出n个数字,表示对每个局面,如果小明先填,当K大师总是用最强着法的时候,小明的最好结果。 1 表示能赢 -1 表示必输 0 表示可以逼平
例如, 输入: 4
*** L**L L**L***L L*****L
则程序应该输出: 0 -1 1 1
资源约定: 峰值内存消耗 < 256M CPU消耗 < 1000ms
请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。
所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。
注意: main函数需要返回0 注意: 只使用ANSI C/ANSI C++ 标准,不要调用依赖于编译环境或操作系统的特殊函数。 注意: 所有依赖的函数必须明确地在源文件中 #include , 不能通过工程设置而省略常用头文件。
提交时,注意选择所期望的编译器类型。
Code/* ^....0 ^ .1 ^1^ .. 01 1.^ 1.0 ^ 1 ^ ^0.1 1 ^ ^..^ 0. ^ 0^ .0 1 .^ .1 ^0 .........001^ .1 1. .111100....01^ 00 11^ ^1. .1^ 1.^ ^0 0^ .^ ^0..1 .1 1..^ 1 .0 ^ ^ 00. ^^0.^ ^ 0 ^^110.^ 0 0 ^ ^^^10.01 ^^ 10 1 1 ^^^1110.1 01 10 1.1 ^^^1111110 010 01 ^^ ^^^1111^1.^ ^^^ 10 10^ 0^ 1 ^^111^^^0.1^ 1....^ 11 0 ^^11^^^ 0.. ....1^ ^ ^ 1. 0^ ^11^^^ ^ 1 111^ ^ 0. 10 00 11 ^^^^^ 1 0 1. 0^ ^0 ^0 ^^^^ 0 0. 0^ 1.0 .^ ^^^^ 1 1 .0 ^.^ ^^ 0^ ^1 ^^^^ 0. ^.1 1 ^ 11 1. ^^^ ^ ^ ..^ ^..^ ^1 ^.^ ^^^ .0 ^.0 0..^ ^0 01 ^^^ .. 0..^ 1 .. .1 ^.^ ^^^ 1 ^ ^0001 ^ 1. 00 0. ^^^ ^.0 ^.1 . 0^. ^.^ ^.^ ^^^ ..0.0 1 .^^. .^ 1001 ^^ ^^^ . 1^ . ^ ^. 11 0. 1 ^ ^^ 0. 0 ^. 0 ^0 1 ^^^ 0. 0.^ 1. 0^ 0 .1 ^^^ .. .1 1. 00 . .1 ^^^ .. 1 1. ^. 0 .^ ^^ .. 0. 1. .^ . 0 . .1 1. 01 . . ^ 0 ^.^ 00 ^0 1. ^ 1 1 .0 00 . ^^^^^^ . .^ 00 01 .. 1. 00 10 1 ^ ^.1 00 ^. ^^^ .1 .. 00 .1 1..01 .. 1.1 00 1. ..^ 10 ^ 1^ 00 ^.1 0 1 1 .1 00 00 ^ 1 ^ . 00 ^.^ 10^ ^^ 1.1 00 00 10^ ..^ 1. ^. 1. 0 1 ^. 00 00 .^ ^ ^. ^ 1 00 ^0000^ ^ 01 1 0 ^. 00.0^ ^00000 1.00.1 11 . 1 0 1^^0.01 ^^^ 01 .^ ^ 1 1^^ ^.^ 1 1 0. .. 1 ^ 1 1 ^ ^ .0 1 ^ 1 .. 1.1 ^0.0 ^ 0 1..01^^100000..0^ 1 1 ^ 1 ^^1111^ ^^ 0 ^ ^ 1 1000^ .1 ^.^ . 00 .. 1.1 0. 0 1. . 1. .^ 1. 1 1. ^0 ^ . ^.1 00 01 ^.0 001. .^ */ // VB_king —— 2017_Finals_A_C++_4.cpp created by VB_KoKing on 2019-05-07:14. /* Procedural objectives: Variables required by the program: Procedural thinking: 深搜剩下的所有可能的情况,根据返回值判断胜负。 Functions required by the program: Determination algorithm: DFS+回溯 Determining data structure: */ /* My dear Max said: "I like you, So the first bunch of sunshine I saw in the morning is you, The first gentle breeze that passed through my ear is you, The first star I see is also you. The world I see is all your shadow." FIGHTING FOR OUR FUTURE!!! */ #include using namespace std; int check(string str) { if (str.find("LOL") != string::npos) return -1; else if (str.find('*') == string::npos) return 0; bool flag = false; for (int i = 0; i < str.length(); i++) { if (str[i] == '*') { str[i] = 'L'; switch (check(str)) { case -1: return 1; case 0: flag = true; break; } str[i] = 'O'; switch (check(str)) { case -1: return 1; case 0: flag = true; break; } str[i] = '*'; } } if (flag) return 0; return -1; } int main() { int n; cin >> n; string str[10]; for (int i = 0; i < n; i++) { cin >> str[i]; } for (int i = 0; i < n; i++) { cout << check(str[i]) << endl; } return 0; }