HDU 4861 Couple doubi (数论)

Couple doubi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
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).
 

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;
}



 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值