Couple doubi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 630 Accepted Submission(s): 449
Total Submission(s): 630 Accepted Submission(s): 449
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).
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
题意:
思路:
源代码
有两个 doubi 的夫妇在取牌比大小,每张牌有一定的点数,且每张牌的点数满足 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).,且p为素数。双方轮流取牌,看最后谁的点数大。
思路:
这是一题打表题,附上打表代码以及源代码,如下:打表代码
/*************************************************************************
> File Name: hdu4861table.cpp
> Author: Bslin
> Mail: Baoshenglin1994@gmail.com
> Created Time: 2014年07月23日 星期三 19时06分44秒
************************************************************************/
#include <stdio.h>
#include <math.h>
int prime[10] = { 2, 3, 5, 7, 11, 13 };
int main(int argc, char *argv[]) {
int k, p, i, j;
int ans;
for (k = 2; k <= 5; ++k) {
for (p = 0; p <= 5; ++p) {
printf("k = %d, p = %d\n", k, prime[p]);
for (i = 1; i <= k; ++i) {
ans = 0;
for (j = 1; j < prime[p]; ++j) {
ans += pow(j, i);
}
ans = ans % prime[p];
printf("num%d: %d\n", i, ans);
}
}
}
return 0;
}
源代码
/*************************************************************************
> File Name: hdu4861.c
> Author: Bslin
> Mail: Baoshenglin1994@gmail.com
> Created Time: 2014年07月23日 星期三 19时34分27秒
************************************************************************/
#include <stdio.h>
int main(int argc, char *argv[]) {
freopen("in.txt", "r", stdin);
int k, p;
while(scanf("%d%d", &k, &p) != EOF) {
if(p == 2) {
if(k % 2) {
printf("YES\n");
} else {
printf("NO\n");
}
} else {
if((k / (p - 1)) % 2) {
printf("YES\n");
} else {
printf("NO\n");
}
}
}
return 0;
}