Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1320588
  • 博文数量: 179
  • 博客积分: 4141
  • 博客等级: 中将
  • 技术积分: 2083
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-21 20:04
文章存档

2024年(1)

2019年(13)

2016年(1)

2014年(16)

2011年(8)

2010年(25)

2009年(115)

分类: C/C++

2019-02-19 23:19:12

Paint Chain

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


Problem Description
Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unable to paint in his turn lose the game. Aekdycoin will take the first move.

Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
 

Input
First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
 

Output
For each case, print "Case #idx: " first where idx is the case number start from 1, and the name of the winner.
 

Sample Input
	
2 3 1 4 2
 

Sample Output
	
Case #1: aekdycoin Case #2: abcdxyzk
 

Author
jayi
 

Source
 

  1. #include <cstdlib>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <memory.h>

  5. using namespace std;

  6. int result[1001];
  7. bool g[1001];

  8. void compute(int count, int paints) {
  9.     int i;

  10.     int subCount = count - paints;

  11.     if (subCount < 0) {
  12.         result[count] = 0;
  13.         return;
  14.     }

  15.     memset(g, false, sizeof(g));

  16.     for (i = 0; i <= subCount && i <= subCount - i; ++i) {
  17.         g[result[i] ^ result[subCount - i]] = true;
  18.     }

  19.     for (i = 0; ;++i) {
  20.         if (g[i] == false) {
  21.             result[count] = i;
  22.             break;
  23.         }
  24.     }
  25. }

  26. int main()
  27. {
  28.     int i, j;

  29.     int num;
  30.     int beads;
  31.     int paints;

  32.     scanf("%d", &num);
  33.     for (i = 0; i < num; ++i) {
  34.         memset(result, -1, sizeof(result));
  35.         scanf("%d %d", &beads, &paints);

  36.         if (paints > beads) {
  37.             printf("Case #%d: abcdxyzk\n", i + 1);
  38.             continue;
  39.         }

  40.         beads -= paints;

  41.         for (j = 0; j <= beads; ++j) {
  42.             compute(j, paints);
  43.         }

  44.         if (result[beads] == 0) {
  45.             printf("Case #%d: aekdycoin\n", i + 1);
  46.         } else {
  47.             printf("Case #%d: abcdxyzk\n", i + 1);
  48.         }
  49.     }

  50.     return 0;
  51. }

阅读(957) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~