题目2267:蓝桥杯2016年第七届真题-取球博弈

#include<iostream>

#include<algorithm>

using namespace std;

int n5, vis100022;

int dfs(int x, int f, int s) {

if(visxf%2s%2 != 2) {

return visxf%2s%2;

}

if(x < n1) { // 不能取球了

if((f%2 == 1) && (s%2 == 0)) return 1;

else if((f%2 == 0) && (s%2 == 1)) return -1;

else return 0;

}

int res;

bool ping = false; // 记录是否有平局可能

for(int i = 1; i <= 3; i++) {

if(x - ni >= 0) {

res = dfs(x - ni, s, f + ni);

if(res == -1) { // 对手输,我赢

visxf%2s%2 = 1;

return 1;

}

if(res == 0) { // 有平局可能

ping = true;

}

}

}

if(ping) { // 没有必胜,但有平局

visxf%2s%2 = 0;

return 0;

}

// 所有选择都导致对手赢

visxf%2s%2 = -1;

return -1;

}

int main() {

cin >> n1 >> n2 >> n3;

sort(n+1, n+4);//排序范围是 n1、n2、n3

for(int i = 1; i <= 5; i++) {

int x;

cin >> x;

// 初始化vis数组

for(int j = 0; j <= x; j++) {

visj00 = visj01 = visj10 = visj11 = 2;

}

int ans = dfs(x, 0, 0);

if(ans == 1) cout << "+ ";

else if(ans == 0) cout << "0 ";

else cout << "- ";

}

return 0;

}

相关推荐
ShineWinsu1 小时前
对于Linux:模版方法类的解析以及socket、TcpSocket的封装
linux·c++·面试·socket·模板方法模式·封装·tcpsocket
稚南城才子,乌衣巷风流2 小时前
ST 表(Sparse Table)算法详解:原理、实现与应用
算法
hold?fish:palm2 小时前
9 找到字符串中所有字母异位词
c++·算法·leetcode
Sw1zzle2 小时前
算法入门(六):贪心算法 - 基础入门(Leetcode 121/455/860/376/738)
算法·leetcode·贪心算法
青山木2 小时前
Hot 100 --- 岛屿数量
java·数据结构·算法·leetcode·深度优先·广度优先
不会就选b3 小时前
算法日常・每日刷题--<归并排序>1
数据结构·算法
危桥带雨3 小时前
排序算法(快排、归并、计数、基数排序)
数据结构·算法·排序算法
啦啦啦啦啦zzzz3 小时前
算法:回溯算法
c++·算法·leetcode
IT探索3 小时前
Linux 查找文件指令总结
linux·算法