多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > POJ1143:Number Game(狀態壓縮)

POJ1143:Number Game(狀態壓縮)

來源:程序員人生   發布時間:2015-05-13 08:15:34 閱讀次數:3704次

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.

Sample Input

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

Source

Mid-Central European Regional Contest 2000

題意:兩人玩游戲,有1些列數,1旦選了某些數字,那末這些數字的倍數和這些數字通過相加能組成的數字都不能選了,當輪到某個人選的時候,沒有數字可以選了,那末這個人就必輸

思路:以狀態緊縮記錄枚舉所有情況來進行搜索便可

#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <algorithm> using namespace std; #define ls 2*i #define rs 2*i+1 #define up(i,x,y) for(i=x;i<=y;i++) #define down(i,x,y) for(i=x;i>=y;i--) #define mem(a,x) memset(a,x,sizeof(a)) #define w(a) while(a) #define LL long long const double pi = acos(⑴.0); #define Len 200005 #define mod 19999997 const int INF = 0x3f3f3f3f; #define exp 1e⑹ int cas = 1; int n,a[25],dp[600000],ans[25],len; int getnum(int s[]) { int ret = 0,i; for(int i = 2;i<=20;i++) { if(s[i]) ret|=1; ret<<=1; } return ret; } int dfs(int s[],int st) { int cpy[25],i,j; memcpy(cpy,s,25*sizeof(int)); cpy[st] = 0; for(i = 2; i+st<=20; i++) { if(!cpy[i]) cpy[i+st] = 0; } int ss = getnum(cpy); if(dp[ss]!=0) { if(dp[ss]>0) return 1; else return 0; } up(i,2,20) { if(cpy[i] && !dfs(cpy,i)) { dp[ss] = 1; return 1; } } dp[ss] = ⑴; return 0; } int main() { int i,j,k; mem(dp,0); w((scanf("%d",&n),n)) { mem(a,0); up(i,1,n) { scanf("%d",&k); a[k] = 1; } int s = getnum(a); len = 0; up(i,2,20) { if(a[i] && !dfs(a,i)) ans[len++] = i; } printf("Test Case #%d ",cas++); if(len) { printf("The winning moves are:"); up(i,0,len⑴) printf(" %d",ans[i]); } else { printf("There's no winning move."); dp[s] = ⑴; } printf(" "); } return 0; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲天堂在线播放 | 日韩欧美视频 | 亚洲国产情侣一区二区三区 | 国产福利不卡视频在免费 | 国产精品亚洲综合一区在线观看 | 日本特一级毛片免费视频 | 99久久精品男女性高爱 | 日本乱性 | 日本一级高清不卡视频在线 | 国产无限资源在线观看 | 国语性猛交xxxx乱大交 | 无人区一区二区三区乱码 | 日本xxxxxbbbbb精品 | 欧美日韩亚洲国内综合网俺 | 一级大黄美女免费播放 | 国产片免费 | 久久一级 | 中文字幕中韩乱码亚洲大片 | a爱爱视频 | 午夜一级做a爰片久久毛片 午夜一区二区三区 | 日韩在线观看一区 | 日本亚洲精品久久 | 亚洲精品一区二区三区婷婷月 | h在线观看免费 | 亚洲一区二区三区夜色 | 国产欧美精品国产国产专区 | japanese日本护士com | 中文字幕色站 | 亚洲久久久久久久 | 国产v片成人影院在线观看 国产v片在线观看 | 日韩欧美在线观看 | 国内精品伊人久久大香线焦 | 国产激情一区二区三区四区 | 噜噜色.com| 国产观看精品一区二区三区 | 性做久久久久久久 | 网站免费视频 | 最近最新高清中文字幕6页 最近最新免费中文字幕8 | xxxwww欧美性 | 欧美一区二区三区四区视频 | 性欧美18 |