Codeforces Gym 100500E IBM Chill Zone
2015-05-12 21:36
337 查看
Codeforces Gym 100500E IBM Chill Zone
A relaxing, fun way to unwind nightly with old and new friends at the ACM-ICPC World Finals is to stop by the IBM Chill Zone! A great way to participate in interactive games and interesting conversation with innovative IBMers and
attendees from all over the world, the IBM Chill Zone is always a favorite for all. Many games can be found in the chill zone, including board game, human-size chess board, real-life angry birds, and stones game.
The stones game was invented by one of ICPC world finalists. It a 2-player game. It consists of a line of n stones and at each move a player should remove k consecutive stones, and if the player can not make any moves he loses, for example if we have n = 6,
k = 2 (stones are represented by ’*’, and empty spaces by ’.’):
First player now has no valid moves, so he loses, but note that he did not play optimally here.
Given n, and k assume both players play optimally well, determine if the first player is losing or winning.
Input
The first line will be the number of test cases T. Each of the following T lines will contain 2 numbers n, k.
1≤T ≤100 1 ≤ n ≤ 50 1≤k≤n
Output
For each test case print a single line containing: Case_x:_y
x is the case number starting from 1.
y is either ’Winning’, or ’Losing’ without the quotes (winning if the first is winning, losing otherwise) Replace underscores with spaces.
Examples
Input
2
5 2
5 3
Output
Case 1: Losing
Case 2: Winning
题意:给连续n个石子,两人轮流拿石子,每次必须取连续的k个石子,在最优策略下询问先手胜负。
做法:SG函数,根据题意写出对应的SG函数,注意VIS数组开在SG转移里头,保证所有的状态之间不会互相干扰。
A relaxing, fun way to unwind nightly with old and new friends at the ACM-ICPC World Finals is to stop by the IBM Chill Zone! A great way to participate in interactive games and interesting conversation with innovative IBMers and
attendees from all over the world, the IBM Chill Zone is always a favorite for all. Many games can be found in the chill zone, including board game, human-size chess board, real-life angry birds, and stones game.
The stones game was invented by one of ICPC world finalists. It a 2-player game. It consists of a line of n stones and at each move a player should remove k consecutive stones, and if the player can not make any moves he loses, for example if we have n = 6,
k = 2 (stones are represented by ’*’, and empty spaces by ’.’):
First player now has no valid moves, so he loses, but note that he did not play optimally here.
Given n, and k assume both players play optimally well, determine if the first player is losing or winning.
Input
The first line will be the number of test cases T. Each of the following T lines will contain 2 numbers n, k.
1≤T ≤100 1 ≤ n ≤ 50 1≤k≤n
Output
For each test case print a single line containing: Case_x:_y
x is the case number starting from 1.
y is either ’Winning’, or ’Losing’ without the quotes (winning if the first is winning, losing otherwise) Replace underscores with spaces.
Examples
Input
2
5 2
5 3
Output
Case 1: Losing
Case 2: Winning
题意:给连续n个石子,两人轮流拿石子,每次必须取连续的k个石子,在最优策略下询问先手胜负。
做法:SG函数,根据题意写出对应的SG函数,注意VIS数组开在SG转移里头,保证所有的状态之间不会互相干扰。
/*written by tomriddly*/ #include <bits/stdc++.h> using namespace std; int n, m; int f[55]; inline int sg(const int &x) { //printf("%d %d\n", x, f[x]); if (f[x] != -1) return f[x]; bool vis[50*50 + 5]; memset(vis, false, sizeof(vis)); for (int i = 1; i + m - 1 <= x; i++) { // printf("%d: %d\n", x, sg(i - 1) ^ sg(x - i - m + 1)); vis[sg(i - 1) ^ sg(x - i - m + 1)] = true; } int i = 0; while (vis[i]) i++; return f[x] = i; } int main() { int fuck; scanf("%d", &fuck); for (int cas = 1; cas <= fuck; cas++) { memset(f, -1, sizeof(f)); scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) f[i] = 0; if (sg(n)) printf("Case %d: Winning\n", cas); else printf("Case %d: Losing\n", cas); } return 0; }
相关文章推荐
- Codeforces Gym 101061 B RGB plants(矩阵快速幂)
- [扫描线 杂题] Codeforces Gym 101190 NEERC 16 E. Expect to Wait
- Codeforces gym 101341I Matrix God【思维】【hash】
- Codeforces Gym 100783D Book Club(匈牙利算法)
- codeforces Gym - 101485 D Debugging (2015-2016 Northwestern European Regional Contest (NWERC 2015))
- codeforces gym 100827A Runes
- codeforces GYM 100971F 公式题或者三分
- Codeforces gym 100971 D. Laying Cables 单调栈
- CodeForces Gym 100989E Accepted Passwords
- codeforces Gym - 101485 D Debugging 记忆化dp
- Codeforces Gym 101505(2016-2017 CTU Open Contest) D---群论、模拟
- CodeForces Gym 100646G The Worm Turns DFS
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
- Codeforces Gym 100463D Evil DFS
- codeforces Gym 100187 A. Potion of Immortality
- Codeforces Gym 100637A A. Nano alarm-clocks 前缀和
- Codeforces Gym 101173 K. Key Knocking (构造)
- codeforces Gym 100500 J. Bye Bye Russia
- Codeforces Gym 100637A A. Nano alarm-clocks 前缀和的利用
- codeforces Gym 100286J Javanese Cryptoanalysis (二染色)