Number Game poj1143
Description
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
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
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的更多相关文章
- [POJ1143]Number Game
[POJ1143]Number Game 试题描述 Christine and Matt are playing an exciting game they just invented: the Nu ...
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- 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.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
随机推荐
- Tkinter教程之Toplevel篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811341 '''Tkinter教程之Toplevel篇'''#TopLevel与Frame类 ...
- Google Appengine参考路径
1.Hello, World! in 5 minutes 2.Creating a Guestbook -Introduction 3.Sample Applications 1.Programmin ...
- 王家林的81门一站式云计算分布式大数据&移动互联网解决方案课程第14门课程:Android软硬整合设计与框架揭秘: HAL&Framework &Native Service &App&HTML5架构设计与实战开发
掌握Android从底层开发到框架整合技术到上层App开发及HTML5的全部技术: 一次彻底的Android架构.思想和实战技术的洗礼: 彻底掌握Andorid HAL.Android Runtime ...
- HDU 5776 sum (模拟)
sum 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5776 Description Given a sequence, you're asked ...
- Hibernate入门(1)-第一个Hibernate程序
Hibernate入门(1)-第一个Hibernate程序 Hibernate是最著名的ORM工具之一,本系列文章主要学习Hibernate的用法,不涉及Hibernate的原理.本文介绍第一个Hib ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- UVa 817 According to Bartjens (暴力,DFS)
题意:给出一个数字组成的字符串,然后在字符串内添加三种运算符号 * + - ,要求输出所有添加运算符并运算后结果等于2000的式子. 所有数字不能有前导0, 且式子必须是合法的. 析:这个题很明显的暴 ...
- Starter Set of Functional Interfaces
Java Development Kit 8 has a number of functional interfaces. Here we review the starter set-the int ...
- c++出错记录
错误1如下: vector<vector<int>> m_vc; error: '&' cannot appear in a constant-expression ...
- .NET Reflector插件FileDisassembler还原源码
NET Reflector,它是一个类浏览器和反编译器,可以分析程序集并向您展示它的所有秘密..NET 框架向全世界引入了可用来分析任何基于 .NET 的代码(无论它是单个类还是完整的程序集)的反射概 ...