首页 > 技术文章 > Couple doubi

serendipity-my 2020-03-30 20:59 原文

Couple doubi

Couple doubi

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 238 Accepted Submission(s): 199

Problem Description

DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of this game is as following. There are k balls on the desk. Every ball has a value and the value of ith (i=1,2,...,k) ball is 1i+2i+...+(p-1)^i (mod p). Number p is a prime number that is chosen by DouBiXp and his girlfriend. And then they take balls in turn and DouBiNan first. After all the balls are token, they compare the sum of values with the other ,and the person who get larger sum will win the game. You should print “YES” if DouBiNan will win the game. Otherwise you should print “NO”.

Input

Multiply Test Cases.
In the first line there are two Integers k and p(1<k,p<2^31).

Output

For each line, output an integer, as described above.

Sample Input

2 3
20 3

Sample Output

YES
NO

分析:首先题目很好理解,有一点需要注意的就是先选的那个人并不是必须选一号球,这样轮流

因为最后比sum的大小------简单博弈

即,第一个人肯定选那个value大的

做题时先列举几个,找一下规律

20 3
0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2
20 5
0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4

仅仅有在p-1的倍数时有非0元素存在。

所以只要分析非零的时候

20 3 --------10 ---平局

20 5 --------5 ---先手胜

所以k/(p-1) 为奇数时先手胜,否则为平局

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k,p;
	while(cin>>k>>p)
	{
		if(k/(p-1)%2)
		{
			cout<<"YES"<<endl;
		}
		else
		cout<<"NO"<<endl;
	}
	return 0;
}

推荐阅读