列表

详情


NC25349. Bash Game

描述

The two new cute boys(Alice and Bob) in the ACM group of HLJU science and technology association have been dreaming of getting these six books written by Mr Jin.

 

As we all know, there is no such thing as a free lunch. Mr Jin now lets Alice and Bob play a game,and only the winner of the game can get these six books.The rules of the game are as follows.

 Suppose(假设) the price of these six books is P, two people take turns in bidding(竞拍), Suppose one party(一方) bid A yuan during the bidding process and the other party(另一方) bid B yuan. Rules require . In this way, the bidding goes on in turn until the price of one party is greater than or equal toP,the party fails and the game ends, Mr Jin awarded these books to another party.

 

Alice first bid, Bob bid behind him every time, and Alice and Bob use the best strategy(最优策略), who can get these books?

输入描述

输出描述

示例1

输入:

4
1 1
20 6
10 2
23 7

输出:

Bob
Alice
Bob
Alice

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 17ms, 内存消耗: 532K, 提交时间: 2020-10-06 13:18:43

#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int p,m;
		cin>>p>>m;
		if((p+m)%(m+1)==0){
			cout<<"Bob"<<endl;
		}else{
			cout<<"Alice"<<endl;
		}
	}
}

Python3(3.5.2) 解法, 执行用时: 173ms, 内存消耗: 3676K, 提交时间: 2019-04-25 16:47:04

T=int(input())
for i in range(T):
    n,m=map(int,input().strip().split(" "))
    if (n-1) % (m+1) == 0:
        print("Bob")
    else:
        print("Alice")

C++11(clang++ 3.9) 解法, 执行用时: 8ms, 内存消耗: 488K, 提交时间: 2020-02-26 13:03:52

#include<cstdio>
int T,n,m;
int main()
{
	for(scanf("%d",&T);T;T--)
	{
		scanf("%d%d",&n,&m);
		if(n%(m+1)==1) puts("Bob");
		else puts("Alice");
	}
}

上一题