NOJ1105Game

Game

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:84            测试通过:18

描述

Carl and Ellie are in the midst of another adventure; this time, it is a road trip through Canada! They’ve just arrived in Saskatchewan [insert rectangular shape here], right in the middle of the Canadian prairies,and, to their horror, have discovered that all the rumours about it being dreadfully flat are true. Suddenly,the warnings their Canadian friends gave them prior to the trip spring back to mind, such as:
It’s so flat, a boy can watch his dog run away!
Or:
It’s so flat, it’s impossible to jump to your death!
As the driver, Carl is worried about falling asleep at the wheel and has decided to come up with a game to relieve the boredom. As a conscientious driver, he doesn’t want the game to be too distracting—the roads here are unerringly straight, so it’s easy to lose track of motion—so the rules are simple:
• Carl picks a number, N, between 1 and 1, 000, 000, 000.
• Carl and Ellie take turns subtracting an integer (between 1 and 20) from N. Carl plays first, and the winner is the one who subtracts off a number to get 0.
For example, suppose Carl picks the number 50. He subtracts off the number 5, leaving 45. Ellie subtracts off 17, leaving 28. Carl subtracts off 8, leaving 20. Finally, Ellie subtracts off 20, leaving 0, and wins!
Frankly, Ellie would rather sleep than play this game, so she has reprogrammed the GPS (which isn’t necessary in this region, anyway) to play for her instead. Her method of choosing a number is straightforward:
• If on a given turn, the number remaining is 20 or less, then she picks that number and wins.
• Otherwise, her choice of number is completely determined by the number Carl just picked, as follows. Before the game starts, Ellie chooses 20 random numbers, 1 ≤ a1, a2, a3, . . . ,a20 ≤ 20. Then whenever Carl subtracts off the number k, Ellie responds by subtracting off the number ak (unless she can win).
Carl needs your help! To help stay motivated playing this game, he would like to know if there exists a winning strategy for him, given the numbers N and a1, a2, a3, . . . ,a20.

输入

Each input case begins with the number N on a line by itself; the next line contains the numbers a1, a2, . . . ,a20, separated by spaces. Input terminates with a line containing 0.

输出

For each test case, print “Carl can win” or “Carl can't win”.

样例输入

42
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
0

样例输出

Carl can't win

提示

In this sample, since Carl chooses N to be 42, it turns out that he has no winning strategy. (Indeed, whichever number he initially subtracts off, Ellie will subtract off a number leaving 21 for Carl. Then whatever number Carl subtracts off next, Ellie will be left with a number between 1 and 20, and she wins!)

题目来源

Cai Wenju && Li Jialong


//Game——Carl先,可以取数组a中的值(可能重复)谁先减到0的win
//关键:whenever Carl选k, Ellie必须选 ak (unless she can win)
#include<stdio.h>

int a[20];
int n;

bool judge()
{
	int i;
	for(i=0;i<10;i++)
	{
		if(a[i] + a[a[i]] == 21) break;
	}
	if(i >= 10) return false;
	return true;
}

int main()
{
	while(scanf("%d",&n) && n)
	{
		for(int i=0;i<20;i++)
			scanf("%d",&a[i]);
		if(n < 21)
			printf("Carl can win\n");
		else if(n == 21)
			printf("Carl can't win\n");
		else if(n > 21 && n % 21 != 0)
			printf("Carl can win\n");
		else // n > 21 && n % 21 == 0
		{
			if(judge() == true)
				printf("Carl can win\n");
			else
				printf("Carl can't win\n");
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值