2017年第八届蓝桥杯C/C++ A组国赛 —— 第四题:填字母游戏
標(biāo)題:填字母游戲
小明經(jīng)常玩 LOL 游戲上癮,一次他想挑戰(zhàn)K大師,不料K大師說:
“我們先來玩?zhèn)€空格填字母的游戲,要是你不能贏我,就再別玩LOL了”。
K大師在紙上畫了一行n個格子,要小明和他交替往其中填入字母。
并且:
小明試驗了幾次都輸了,他很慚愧,希望你能用計算機幫他解開這個謎。
本題的輸入格式為:
第一行,數(shù)字n(n<10),表示下面有n個初始局面。
接下來,n行,每行一個串(長度<20),表示開始的局面。
比如:“******”, 表示有6個空格。
“L****”, 表示左邊是一個字母L,它的右邊是4個空格。
要求輸出n個數(shù)字,表示對每個局面,如果小明先填,當(dāng)K大師總是用最強著法的時候,小明的最好結(jié)果。
1 表示能贏
-1 表示必輸
0 表示可以逼平
例如,
輸入:
4
則程序應(yīng)該輸出:
0
-1
1
1
資源約定:
峰值內(nèi)存消耗 < 256M
CPU消耗 < 1000ms
請嚴格按要求輸出,不要畫蛇添足地打印類似:“請您輸入…” 的多余內(nèi)容。
所有代碼放在同一個源文件中,調(diào)試通過后,拷貝提交該源碼。
注意: main函數(shù)需要返回0
注意: 只使用ANSI C/ANSI C++ 標(biāo)準,不要調(diào)用依賴于編譯環(huán)境或操作系統(tǒng)的特殊函數(shù)。
注意: 所有依賴的函數(shù)必須明確地在源文件中 #include , 不能通過工程設(shè)置而省略常用頭文件。
提交時,注意選擇所期望的編譯器類型。
Code
/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^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.101 10 1.1 ^^^1111110010 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. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 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^ ^ 011 0 ^. 00.0^ ^00000 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 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:深搜剩下的所有可能的情況,根據(jù)返回值判斷勝負。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 <iostream>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; }總結(jié)
以上是生活随笔為你收集整理的2017年第八届蓝桥杯C/C++ A组国赛 —— 第四题:填字母游戏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2017年第八届蓝桥杯C/C++ A组国
- 下一篇: 2017年第八届蓝桥杯C/C++ C组国