书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

有点意思的Game

题目:http://acm.swust.edu.cn/oj/problem/836/

直接上代码,不解释。

View Code
#include "iostream"
#include "cstring"
#include "string"
#include "cstdio"
#include "cmath"
#include "algorithm"
using namespace std;
int a[1005];
bool IsPrime(int x){
    for(int l=2; l<=sqrt(double(x)); l++){
        if(x%l==0) return false;
    }
    return true;
}
int main(){
    int n, k;
    while(cin>>n>>k){
        if(k>=n){
            cout<<"WIN"<<endl;
            continue;
        }
        memset(a, 0, sizeof(a));
        a[0] = -1;
        for(int i=1; i<=k; i++){
            a[i] = 1;
        }
        //在我取的范围内,只要它不能使我输, 那么我就赢了
        for(int i=k+1; i<=n; i++){
            int WinI = 0;
            for(int j=1; j<=k; j++){
                int tk = k;
                if(IsPrime(i-j)) tk++;
                int WinJ = 1;
                for(int l=1; l<=tk; l++){
                    if(i-j-l>=0 && a[i-j-l]==-1){
                        WinJ = 0; //I Lose;
                        break;
                    }
                }
                if(WinJ==1){
                    WinI = 1; //Win;
                    break;
                }
            }
            if(WinI==1) a[i]=1;
            else a[i]=-1;
        }
        if(a[n]==1) cout<<"WIN"<<endl;
        else cout<<"LOSE"<<endl;
    }
}

posted on 2012-04-28 20:40  More study needed.  阅读(156)  评论(0编辑  收藏  举报

导航

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!