HDU4861 Couple doubi 【找规律】

Couple doubi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 723    Accepted Submission(s): 522

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

在演草纸上分别列出p为3、5、7的情况,可以找到规律,即周期为p-1,每p-1个数里面只有一个数不等于0,于是可以求有多少个周期,周期数为奇数则先手赢。

#include <stdio.h>
#include <math.h>
int main()
{
    int k, p;
    while(scanf("%d%d", &k, &p) != EOF){
        if(k / (p-1) % 2) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
时间: 2024-10-31 13:59:04

HDU4861 Couple doubi 【找规律】的相关文章

hdu 4861 Couple doubi (找规律 )

题目链接 可以瞎搞一下,找找规律 题意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+?+(p−1)i%p,两个人轮流取,如果DouBiNan的值大的话就输出YES,否则输出NO. 分析:解题报告 1 #include <cstdio> 2 #include <iostream> 3 4 using namespace std; 5 int main() 6 { 7 int k, p; 8 while(cin>>k>>p) 9 { 10 if(k/

HDU 4861 Couple doubi(找规律|费马定理)

Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4861 Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of th

hdu4861 我只能说这是找规律=.=

先说明一下题意,因为开始我就没太读懂,感觉作者不是没交代清楚就是让做题的人自己去领悟,开始我不知道球是可以随便选的,然后那个关系式到底是最后一个数模p,还是整体模P........最后确定是整体模P 一开始的思路就是找规律,找公式,由于数据非常大不可能用循环,但推了好久也没发现什么公式.....逼得没办法了我就想是不是随便找几个n 再找几个素数把答案都列出来看一下?   但由于工程有点庞大,我就去看了下题解........但我居然看打了费马小定理,作为一个只会高中数学的渣渣,表示费马小定理是什么

HDU-4861 Couple doubi

http://acm.hdu.edu.cn/showproblem.php?pid=4861 Couple doubi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 675    Accepted Submission(s): 484 Problem Description DouBiXp has a girlfriend named

The Cow Lineup_找规律

Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4

UVA - 1646 - Edge Case(找规律)

题意:n(3 <= n <= 10000)个结点组成一个圈,求匹配(即没有公共点的边集)的个数. 找规律为斐波那契的性质,因为数太大所以用的java大数. import java.math.BigInteger; import java.util.Scanner; public class Main{ public static int MAXN = 10000 + 10; public static BigInteger []c = new BigInteger[MAXN]; public

【55测试】【字符串】【栈】【找规律】

集训第二天,额,考崩了. 第一题 hao 大意:(这个名字就不要在意了,其实是祖玛游戏) 模拟祖玛游戏的模式,给一个'A'~'Z'的字符串,然后有t个插入操作为 “ 添加后的在原字符串的位置 x  插入元素 c ”,字符串中有超过或等于 3 个相同的字符,则被消除,输出每次操作后剩余的字符串,如果为空,则输出“-”. 样例: ACCBA                     输出:  ABCCBA 5   AABCCBA 1 B AABBCCBA 0 A - 2 B A 4 C 0 A 解:

2016(胡赛复现)_大数找规律

Time Limit: 5 Sec  Memory Limit: 128 MB Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m;  2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤109). Output 对于每组数据,输出一个整数表示满足条件的数量. Sample Input 32 63 2016 2016 1000000000 1000

HDU 5703 Desert 水题 找规律

已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>

找规律/hdu 1005 Number Sequence

题意 给出a,b,n,已知f[1]=f[2]=1,f[i]=(a*f[i-1]+b*f[i-2]) mod 7 输出f[n] 数据范围 1 <= A, B <= 1000, 1 <= n <= 100,000,000 分析 首先,直接求..肯定是不行的 会tle 会mle 但是可以找到规律,例如对a=1,b=1 这个数据,有 f1=1 f2=1 f3=3 f4=5 f5=4 f6=0 f7=1 f8=1 f9=3 f10=5 f11=4 f12=0 ???? 我们会发现有一定的规律