湖大暑假训练赛2:The Stones Game

107 篇文章 0 订阅
37 篇文章 0 订阅

The Stones Game
Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB
Total submit users: 28, Accepted users: 26
Problem 12828 : No special judgement
Problem description

The stones game is a simple game, it is also a very old game which is unknown to almost everyone. The game starts with N stones and M players, the players are numbered from 1 to M. The players play in turns, player number 1 plays first, then player number 2 and so on until player number M plays, after this player number 1 plays again and they keep playing until the end of the game.
For each turn, the players do the following 2 steps:
1. The player gets a chance to remove a stone, and he/she should remove a stone in this step if he/she decided to do so.
2. Regardless of the decision of the current player (whether or not he/she removed a stone in the first step), if this is not the first turn and in the previous turn the player decided not to remove a stone in his/her first step, then the current player must remove a stone in this step (if in the previous turn the player decided to remove a stone in his/her first step, then the current player must not remove a stone in this step).
This means in some turns a player might remove 0, 1 or 2 stones according to the above rules. In this game, the player who removes the last stone wins the game.
Now you are given the total number of stones, the total number of players and a player number and you are asked to answer the following question:
Is there a strategy for this player to win the game regardless of the actions taken by the other players in their turns?


Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases T ranges in(1,100). Followed by the test cases, each test case is described in one line which contains 3 integers separated by a single space N M X (N,M ranges in(1,10^9) and X ranges in(1,M)) representing the number of stones, the number of players and the player number, respectively.


Output

For each test case, print a single line which contains a single word, this word is either “YES” or “NO” (without the quotes) representing the answer for the above question for the given player number.


Sample Input
2
2 2 2
2 2 1
Sample Output
YES
NO
Problem Source
ACPC 2013

题意:有n个石头,m个人,问第k个人有没有必胜的状态。m个人轮流取石子,一轮没取完第一个人接着取,直到石子没有了。每个人取石子有2个操作。

1、可以选择取一个石子或者不取(0 or 1);

2、如果前一个人(当然第一个人除外,因为他没有前人,嘻嘻。。)的第一次操作取了石子,那么当前这个人这次不能取,反之必须取。也就是说,如果前一个人没有取一个石子,那么当前这个人这次必须取1个石子+你第一次操作选择取or不取。

问最后一个石子被取完的算赢。

题解:模拟每个人的必胜状态的石子个数。第一个人肯定只能两种选择0 or 1,那么第二个人的必胜状态的石子个数就肯定是2.因为无论第一个人怎么取,取不完并且第二个人都能取完。然后总结前两个人分别最少,最多取多少石子,很容易看出来是1 or 2。如果前两个人只取了1个石子,那么第三个人当前操作肯定能取2个石子,如果前两个拿了2个石子,那么第三个人也能拿一个石子,所以必胜状态是3.第四个人满足前面的状态是。前三个人最少,最大,分别能取2个,3个。第四个人想赢就肯定是得4个石子。如果前三个人取2个石子的话,1 2 3的取石子的状态分别是1 0 1或者0 1 1,所以第四个人都可以拿到2个,完成双杀。以此类推。推到这里我们就发现了规律,第K个人必胜的状态就是K个石子。而且前N个人最多拿到的石子是N个。可得如果N>M的话,求余在与K比较即可。当然如果一开始N小于k的话,就直接可以Gg了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
#define LL __int64
int main()
{
    int T,n,m,k;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d%d",&n,&m,&k);
        if (k>n) cout<<"NO"<<endl;
        else
        if (n % m==k || (n%m==0 && m==k)) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值