Description

Christine and Matt are playing an exciting game they just invented: the Number Game. The rules of this game are as follows. 
The players take turns choosing integers greater than 1. First, Christine chooses a number, then Matt chooses a number, then Christine again, and so on. The following rules restrict how new numbers may be chosen by the two players:

  • A number which has already been selected by Christine or Matt, or a multiple of such a number,cannot be chosen.
  • A sum of such multiples cannot be chosen, either.

If a player cannot choose any new number according to these rules, then that player loses the game. 
Here is an example: Christine starts by choosing 4. This prevents Matt from choosing 4, 8, 12, etc.Let's assume that his move is 3. Now the numbers 3, 6, 9, etc. are excluded, too; furthermore, numbers like: 7 = 3+4;10 = 2*3+4;11 = 3+2*4;13 = 3*3+4;... are also not available. So, in fact, the only numbers left are 2 and 5. Christine now selects 2. Since 5=2+3 is now forbidden, she wins because there is no number left for Matt to choose. 
Your task is to write a program which will help play (and win!) the Number Game. Of course, there might be an infinite number of choices for a player, so it may not be easy to find the best move among these possibilities. But after playing for some time, the number of remaining choices becomes finite, and that is the point where your program can help. Given a game position (a list of numbers which are not yet forbidden), your program should output all winning moves. 
A winning move is a move by which the player who is about to move can force a win, no matter what the other player will do afterwards. More formally, a winning move can be defined as follows.

  • A winning move is a move after which the game position is a losing position.
  • A winning position is a position in which a winning move exists. A losing position is a position in which no winning move exists.
  • In particular, the position in which all numbers are forbidden is a losing position. (This makes sense since the player who would have to move in that case loses the game.)

Input

The input consists of several test cases. Each test case is given by exactly one line describing one position. 
Each line will start with a number n (1 <= n <= 20), the number of integers which are still available. The remainder of this line contains the list of these numbers a1;...;an(2 <= ai <= 20). 
The positions described in this way will always be positions which can really occur in the actual Number Game. For example, if 3 is not in the list of allowed numbers, 6 is not in the list, either. 
At the end of the input, there will be a line containing only a zero (instead of n); this line should not be processed.

Output

For each test case, your program should output "Test case #m", where m is the number of the test case (starting with 1). Follow this by either "There's no winning move." if this is true for the position described in the input file, or "The winning moves are: w1 w2 ... wk" where the wi are all winning moves in this position, satisfying wi < wi+1 for 1 <= i < k. After this line, output a blank line.
2 2 5
2 2 3
5 2 3 4 5 6
0

Sample Output

Test Case #1
The winning moves are: 2 Test Case #2
There's no winning move. Test Case #3
The winning moves are: 4 5 6
此题还未AC,但算法没错,等下检查、
 #include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int ms=;
int map[ms];
int mask[];
int judge(int num)
{
int i,j;
if(map[num]==-)
{
map[num]=;
for(i=;i<=;i++)
if((num&mask[i])!=)
{
int tmp=num;
j=i;
while(j<=)
{
tmp&=(((num|)<<j)|(mask[j]-));
j+=i;
}
int c=judge(tmp);
if(c==)
map[num]+=mask[i];
}
}
return map[num];
}
int main()
{
int i,j,ans,x,n,p=,num;
map[]=;
for(i=;i<;i++)
mask[i+]=<<i;
while(scanf("%d",&n)&&n)
{
for(x=,i=;i<=n;i++)
{
scanf("%d",&num);
x|=mask[num];
}
printf("Test Case #%d\n",p++);
ans=judge(x);
if(ans==)
{
printf("There's no winning move.\n\n");
}
else
{
printf("The winning moves are:");
for(i=;i<=;i++)
{
if(ans%==)
printf(" %d",i);
ans>>=;
if(ans==)
{
printf("\n\n");
break;
}
}
}
}
return ;
}
 

Number Game poj1143的更多相关文章

  1. [POJ1143]Number Game

    [POJ1143]Number Game 试题描述 Christine and Matt are playing an exciting game they just invented: the Nu ...

  2. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  3. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  4. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  5. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  6. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  7. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  8. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  9. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

随机推荐

  1. 微信公众平台开发(57)Emoji表情符号

    微信公众平台开发 微信公众平台开发模式 企业微信公众平台 Emoji表情符号 作者:方倍工作室 地址:http://www.cnblogs.com/txw1958/p/crack-golden-egg ...

  2. Windows Azure Platform (一) 云计算的出现

    <Windows Azure Platform 系列文章目录> 最近的一年一直致力于微软云计算技术的推广和研究,对于微软的云计算平台Windows Azure Platform有一定的了解 ...

  3. Could not bind factory to JNDI

    将hibernate.cfg.xml中 <session-factory name="SessionFactory">的name属性去掉即可

  4. HTML5每日一练之input新增加的5种其他类型1种标签应用

    今天介绍input在HTML5中的最后5种类型,分别是:number,range,search,tel和color 注意:此种类型的input在Opera10+中效果为佳,Chrome中效果不是十分好 ...

  5. hibernate 打印sql和参数的配置

    1.配置spring-hiberbate.xml:<prop key="hibernate.show_sql">true</prop>--强制打印sql 不 ...

  6. red5下nginx安装配置

    http://zfl110.iteye.com/blog/1155149 原址:http://lqw.iteye.com/blog/652763 安装Nginx 1.首先安装pcre-8.02.tar ...

  7. Linux下c/c++项目代码覆盖率的产生方法

    最近做了一系列的单元测试相关的工作,除了各种规范及测试框架以外,讨论比较多的就是关于代码覆盖率的产生,c/c++与其他的一些高级语言或者脚本语言相比较而言,例如 Java..Net和php/pytho ...

  8. upload.php --->文件上传

    <?php header("Content-type:text/html;charset=utf-8"); print_r($_FILES['file']); $filena ...

  9. HDU 3974 Assign the task (DFS序 + 线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 给你T组数据,n个节点,n-1对关系,右边的是左边的父节点,所有的值初始化为-1,然后给你q个操 ...

  10. SQLite使用事务更新—by command

    public void SaveToDB(DataTable dt) { /* todo:sqlite没有提供批量插入的机制,需要通过事务处理 更新所有数据 * http://www.cnblogs. ...