当前位置:网站首页>A. Alice and Bob (game? Thinking & Violence) (2021 Niuke summer multi school training camp 1)
A. Alice and Bob (game? Thinking & Violence) (2021 Niuke summer multi school training camp 1)
2022-04-22 07:30:00 【S atur】

The question :Alice First of all , And Bob Take turns to pick up stones , Take it out of a pile of stones at a time k(k>0) A stone is taken out of another pile k*s(s>=0) Stone . Who can't operate, who loses the game .
Ideas : To be honest, I don't know how to write this game , It's said that many people in the game have played this question ( It's amazing ). After the game, I found out that this problem can be solved by violence .
We initialize the tag f[i][j] ==1 Indicates that the initial two piles of stones are i and j It is a must win state , On the contrary, it is a necessary state . And then we enumerate i and j, Then enumerate k and s Handle f[i+k][j+k*s] and f[i+k*s][j+k] ( Because the initial exchange state of the two piles of stones is the same ).
Finally, pay attention to the duration of the input / output card .
Code implementation :
#include<bits/stdc++.h>
using namespace std;
const int N = 5010;
inline void read(int &x){
char t=getchar();
while(!isdigit(t)) t=getchar();
for(x=t^48,t=getchar();isdigit(t);t=getchar()) x=x*10+(t^48);
}
int T = 1, n, m;
bool f[N][N];
int main()
{
for(int i = 0; i <= 5000; i ++){
for(int j = 0; j <= 5000; j ++){
if(!f[i][j]){
for(int k = 1; i+k <= 5000; k ++)
for(int s = 0; j+k*s <= 5000; s ++)
f[i+k][j+k*s] = 1;
for(int k = 1; j+k <= 5000; k ++)
for(int s = 0; i+k*s <= 5000; s ++)
f[i+k*s][j+k] = 1;
}
}
}
read(T);
while(T --){
read(n); read(m);
if(f[n][m]) puts("Alice");
else puts("Bob");
}
return 0;
}
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220616060264.html
边栏推荐
猜你喜欢

Leetcode - 8 - (sum of three numbers, zigzag transformation, sum of two numbers < linked list >, container with the most water, letter combination of telephone number)

A.Binary Seating (概率) (2021年度训练联盟热身训练赛第五场)

The only storage area in the JVM where GC and oom will not occur

Leetcode - 5 - (repeated substring < KMP >, longest palindrome substring, transpose matrix, binary tree (left and right) view)

1005 Monopoly 同余求解(2021中国大学生程序设计竞赛CCPC-网络选拔赛重赛)

Virtual machine disk space shrinks

队列(详解)——手撕队列习题

What is the internal structure of stack frame?

小游戏——三子棋

并发编程的艺术(6):详解ReentrantLock的原理
随机推荐
Cannot find interface mapping after updating HDF
296 · 数组去重
Hand tearing algorithm -- LRU cache elimination strategy, asked so often
Points for attention in Modelsim simulation acceleration
(1) Download and installation of SQL Server
1242 · 无重叠区间
189. Rotation array
L2-002 linked list weight removal (pit of test point 1)
Educational Codeforces Round 122 (Rated for Div. 2)
Escape analysis in JVM can realize that memory is not allocated on the heap
LeetCode - 8 - (三数之和、Z字形变换、两数之和<链表>、盛最多水的容器、电话号码的字母组合)
带环链表详解
C language | pointer
Unknown graphics extension:. 1 jpg. }
Links summary qwq
What is the internal structure of stack frame?
B. Ball Dropping (简单几何计算 / 相似三角形) (2021牛客暑期多校训练营1)
接口的讲解以及使用
867 · 四键键盘
CF1547E Air Conditioners