hdoj 4861 Couple doubi 【打表找规律】

本文介绍了一个涉及数学博弈的问题,通过分析球的价值计算方法和游戏规则,探讨了在特定条件下先手玩家是否能确保胜利的策略。该问题与数论中的费马小定理相关,并提供了一种简洁的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Couple doubi

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


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 1^i+2^i+...+(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
 

Author
FZU
 


题意:有k个球,第i个球的价值 = 1^i + ... + (p-1)^i mod p。有两个人轮流取球,最后比较价值和,价值和大的赢。问先手有没有希望赢。


思路:打表。。。不过应该是一道和费马小定理有关的数论推导。


AC代码:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 1000000
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (100000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while((a)--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
#pragma comment(linker, "/STACK:102400000,102400000")
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
//LL Pow(LL a, LL n, LL p)
//{
//    LL ans = 1LL;
//    while(n)
//    {
//        if(n & 1)
//            ans = ans * a % p;
//        a = a * a % p;
//        n >>= 1;
//    }
//    return ans;
//}
//int main()
//{
//    // p = 3  0 2 0 2 0 2 ......
//    // p = 5  0 0 0 4 0 0 0 4 ......
//    // p = 7  0 0 0 0 0 6 ......
//    int k = 10;
//    for(int i = 1; i <= 10; i++)
//    {
//        LL ans = 0;
//        for(int j = 1; j <= 6; j++)
//            ans = (ans + Pow(j, i, 7)) % 7;
//        printf("%lld ", ans);
//    }
//    return 0;
//}
int main()
{
    int k, p;
    while(scanf("%d%d", &k, &p) != EOF)
    {
        bool flag = (k / (p-1)) & 1;
        printf(flag ? "YES\n" : "NO\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值