版本比较
题解:AT1202Contest_b vs. DEGwer
正文
增加 8 行删除 8 行
7 行未改动89101112131213141516151617181920212223242425262728282930313233333435363737383940418 行未改动7 行未改动交互处理:
使用$cout.flush()$确保输出立即发送到交互器 通过 cin 读取大魔王的操作回应,这段代码针对问题中的特殊情况($2$\times$1$ 迷宫且我方先手)提供了一种必胜策略,而对于其他情况则判断为无法保证胜利,是一个针对性的解决方案。 代码实现:```#include <iostream> #include <string> #include <iostream>#include <string>using namespace std;int main() { int H, W; int main() {int H, W;string move;cin >> H >> W >> move;
// 关键观察:当H=2且W=1且我方先手时,有必胜策略if (H == 2 && W == 1 && move == "First") { cout << "Yes" << endl; cout.flush();
// 第一步:打开第一行入口门 cout << "| 1 1" << endl; cout.flush();
// 读取大魔王的回应 char t; int i, j; cin >> t >> i >> j;
// 第二步:打开第二行出口门 cout << "| 2 2" << endl; cout.flush();
// 读取最终结果 cin >> t >> i >> j;} else { // 其他情况无法保证胜利8 行未改动