当前位置:网站首页>Alice and Bob (2021牛客暑期多校训练营1)
Alice and Bob (2021牛客暑期多校训练营1)
2022-07-06 09:25:00 【是小张张呀 zsy】
Alice and Bob
2021牛客暑期多校训练营1第一题,当时没做出来,看了这个博主的博客,瞬间懂了
题目链接:https://ac.nowcoder.com/acm/contest/11166/A
来源:牛客网
题目描述
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.
输入描述:
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.
输出描述:
For each test case, print “Alice” if Alice will win the game, otherwise print “Bob”.
示例1
输入
复制
5
2 3
3 5
5 7
7 5
7 7
输出
复制
Bob
Alice
Bob
Bob
Alice
题目大意:
两人博弈,每次一个人从一堆中拿走一个,同时从另一堆中拿走k*s个,问能谁先不能拿;
思路:
枚举,暴力,其实思路还是很简单的,如果能一次操作能取光石头此时为必胜态,我们用一个二维数组f[i][j]来表示第一堆石头数量为i第二堆石头数量为j的情况,f[i][j]=1表示状态面临两堆石头数量为i,j时可以一步取光石头,f[i][j]=0表示状态面临两堆石头数量为i,j时无法一次取光石头。根据题目f[k][sk]或f[sk][k]一定能够一次性取完,所以枚举s与k找出所有先手必胜的状态
#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;
}
}
边栏推荐
- [C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
- 程序员的你,有哪些炫技的代码写法?
- Learning records: serial communication and solutions to errors encountered
- LeetCode#36. Effective Sudoku
- Leetcode notes - dynamic planning -day6
- Scoring system based on 485 bus
- 51 lines of code, self-made TX to MySQL software!
- Interview answering skills for software testing
- UCORE Lab 1 system software startup process
- Research Report on pharmaceutical R & D outsourcing service industry - market status analysis and development prospect forecast
猜你喜欢

Want to change jobs? Do you know the seven skills you need to master in the interview software test

VS2019初步使用
How to do agile testing in automated testing?

Scoring system based on 485 bus

Introduction to safety testing

学习记录:理解 SysTick系统定时器,编写延时函数

学习记录:使用STM32F1看门狗

STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)

Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
Interview answering skills for software testing
随机推荐
MATLAB实例:阶跃函数的两种表达方式
China medical check valve market trend report, technical dynamic innovation and market forecast
China's PCB connector market trend report, technological innovation and market forecast
LeetCode#412. Fizz Buzz
csapp shell lab
JS --- all knowledge of JS objects and built-in objects (III)
Want to change jobs? Do you know the seven skills you need to master in the interview software test
Unpleasant error typeerror: cannot perform 'ROR_‘ with a dtyped [float64] array and scalar of type [bool]
Accounting regulations and professional ethics [2]
cs零基础入门学习记录
Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
ucore lab 2
C4D quick start tutorial - creating models
Jupyter installation and use tutorial
Cost accounting [13]
What to do when programmers don't modify bugs? I teach you
学习记录:STM32F103 时钟系统概述工作原理
毕业才知道IT专业大学生毕业前必做的1010件事
C语言数组的概念
LeetCode#268. Missing numbers