uva 11249 - Game

Game

Input: Standard Input

Output: Standard Output

 

 

Alice and Bob are playing a 2 player game. The game has the following rules.

  • It consists of 2 stone piles containing a and b number of stones.
  • In each turn a player can take stones from a single pile or both pile. If she takes stones from 1 pile then she can take up to all the stones from that pile. If she wants to take stones from both piles than the absolute difference between the number of stones taken from each pile can be at most k. In both cases she should take at least one stone.
  • The player who takes the last stones wins.

 

You are given the information about the game. Alice is the first player. You have to determine whether she will win or lose.

 

Input

First line of the input contains T (1≤T≤10) the number of test case. Then following lines contains T Test cases.

 

Each case starts with line containing 2 integers k (1≤k≤20) and q (1≤q≤10000). Each of the next q lines will contains 2 integers a and b (1≤a,b≤100000). Each of these a and b pair along with the initial k will be instance of a game.

 

Output

For each game output will be a single line containing a stringing “WINNING” if Alice can win that game or “LOSING” if she can not win that game. Output a blank line after each test case.

 

 

Sample Input                            Output for Sample Input

1

1 4

2 5

2 6

1 3

1 4

 

WINNING

LOSING

LOSING

WINNING

 


Problemsetter: Abdullah al Mahmood

Special Thanks: Derek Kisman

 找规律的问题。从小的必败局面推更大的。每个样例后面要输出一空行!

#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
#include <stack>
#include <set>
#include <cstring>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 100000 + 5;
const int INF = 1000000000;

int f[maxn*100];

void pre(int k){
    memset(f, -1, sizeof f);
    f[1] = k+2;
    int last = 1;
    f[k+2] = 0;
    for(int i = 2;i < maxn;i++){
        if(f[i] == 0) continue;
        f[i] = f[last]+k+1+i-last;
        last = i;
        f[f[i]] = 0;
    }
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int k,q;
        cin >> k >> q;
        pre(k);
        while(q--){
            int a, b;
            cin >> a >> b;
            if(a > b) swap(a, b);
            if(f[a] == b){
                cout << "LOSING" << endl;
            }
            else{
                cout << "WINNING" << endl;
            }
        }
        cout << endl;
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值