Codeforces Gym 100500E IBM Chill Zone
来源:互联网 发布:windows正版验证网站 编辑:程序博客网 时间:2024/05/16 07:19
Codeforces Gym 100500E IBM Chill Zone
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.
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
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 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;}
0 0
- Codeforces Gym 100500E IBM Chill Zone
- Codeforces Gym100500 Problem E. IBM Chill Zone (博弈)
- CodeForces Gym 100735E
- Codeforces gym 100685 E
- codeforces [Gym-100814E]
- Codeforces gym 101243 E
- codeforces-gym-100187-E【bfs】
- CodeForces Gym 100989E Accepted Passwords
- CodeForces Gym 100646E Su-Su-Sudoku
- 【codeforces】gym 101137 E - Economy Printing【dp】
- Codeforces Gym 101234E Lines Game
- Codeforces Gym-101161E【LCA+主席树】
- Codeforces Gym 100623E Problem E. Enchanted Mirror
- Codeforces Gym 100796E Permutation Polygon(线段树)
- 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)
- 【模拟】NEERC15 E Easy Problemset (Codeforces GYM 100851)
- 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)
- [构造] Codeforces Gym 100553 NEERC 14 E. Epic Win!
- 【C++】派生类对象初始化基类的引用
- java web 中error页面的配置
- Java 设计模式 -- 复合模式之一
- leetcode-Longest Palindromic Substring
- 10块设备驱动程序的编写
- Codeforces Gym 100500E IBM Chill Zone
- threadlocal 作用
- 机器学习--AdaBoost元算法
- 2-19
- 使用strace调试程序
- MFC:RichEdit and CFindReplaceDialog
- matlab调用笔记本摄像头拍照并连续保存
- 一个错误导致的python血案
- 部署描述文件web.xml解析(二) Servlet生命周期