当前位置:网站首页>Alice and Bob (2021 Niuke summer multi school training camp 1)
Alice and Bob (2021 Niuke summer multi school training camp 1)
2022-07-06 16:02:00 【It's Xiao Zhang, ZSY】
Alice and Bob
2021 Niuke summer multi school training camp 1 The first question is , I didn't do it at that time , Read this blogger's blog , I understand instantly.
Topic link :https://ac.nowcoder.com/acm/contest/11166/A
source : Cattle from
Title Description
Alice and Bob like playing games. There are two piles of stones with numbers n and m. Alice and Bob take turns to operate, each operation can take away k(k>0) stones from one pile and take away s×k(s≥0) stones from another pile. Alice plays first. The person who cannot perform the operation loses the game.
Please determine who will win the game if both Alice and Bob play the game optimally.
Input description :
The first line contains an integer T(1≤T≤10^4 ) denotes the total number of test cases.
Each test case contains two integers n,m(1≤n,m≤5×10^ 3) in a line, indicating the number of two piles of stones.
Output description :
For each test case, print “Alice” if Alice will win the game, otherwise print “Bob”.
Example 1
Input
Copy
5
2 3
3 5
5 7
7 5
7 7
Output
Copy
Bob
Alice
Bob
Bob
Alice
The main idea of the topic :
A game of two , Each time one person takes one from the pile , At the same time, take it away from another pile k*s individual , Ask who can take it first ;
Ideas :
enumeration , violence , In fact, the idea is very simple , If you can take all the stones in one operation, you will win at this time , We use a two-dimensional array f[i][j] To indicate that the number of stones in the first pile is i The number of stones in the second pile is j The situation of ,f[i][j]=1 Indicates that the state faces two piles of stones, and the number is i,j You can take all the stones in one step ,f[i][j]=0 Indicates that the state faces two piles of stones, and the number is i,j You can't take all the stones at once . According to the title f[k][sk] or f[sk][k] It must be able to take it all at once , So enumeration s And k Find out the status of all the first to win
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
bool f[5001][5001];
int main()
{
for(int i=0;i<=5000;i++)
{
for(int j=0;j<=5000;j++)
{
if(f[i][j]==0)
{
for(int k=1;k+i<=5000;k++)
{
for(int s=0;s*k+j<=5000;s++)
f[i+k][j+s*k]=1;
}
for(int k=1;k+j<=5000;k++)
{
for(int s=0;s*k+i<=5000;s++)
f[i+s*k][j+k]=1;
}
}
}
}
int t,n,m;
cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
if(f[n][m]==0)
cout<<"Bob"<<endl;
else
cout<<"Alice"<<endl;
}
}
边栏推荐
- China's earthwork tire market trend report, technical dynamic innovation and market forecast
- [exercise-5] (UVA 839) not so mobile (balance)
- 信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
- Opencv learning log 19 skin grinding
- 【练习-2】(Uva 712) S-Trees (S树)
- Accounting regulations and professional ethics [4]
- Determine the Photo Position
- Borg Maze (BFS+最小生成树)(解题报告)
- 洛谷P1102 A-B数对(二分,map,双指针)
- B - 代码派对(女生赛)
猜你喜欢

7-1 懂的都懂 (20 分)

Information security - Analysis of security orchestration automation and response (soar) technology
![[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class](/img/3b/dc43564a36f82e73826b08f39c935e.png)
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class

Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures

Penetration test (7) -- vulnerability scanning tool Nessus

Gartner: five suggestions on best practices for zero trust network access
![[exercise-5] (UVA 839) not so mobile (balance)](/img/8e/48dcf75f7347b36301df6fc129c09d.png)
[exercise-5] (UVA 839) not so mobile (balance)
![[exercise-4] (UVA 11988) broken keyboard = = (linked list)](/img/59/78ca7170ab1fd364ec44cfbcdc7ab5.png)
[exercise-4] (UVA 11988) broken keyboard = = (linked list)

1010 things that college students majoring in it must do before graduation

TCP的三次握手与四次挥手
随机推荐
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Opencv learning log 15 count the number of solder joints and output
Common configuration files of SSM framework
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
Path problem before dynamic planning
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
Cost accounting [23]
Gartner:关于零信任网络访问最佳实践的五个建议
Cost accounting [13]
Nodejs+vue online fresh flower shop sales information system express+mysql
用C语言写网页游戏
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
B - 代码派对(女生赛)
入门C语言基础问答
Shell脚本编程
Truck History
渗透测试 ( 4 ) --- Meterpreter 命令详解
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class