博弈_______Stone Game(hdu 4387)
来源:互联网 发布:js时间段选择控件 编辑:程序博客网 时间:2024/06/05 14:52
Stone Game
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 862 Accepted Submission(s): 340
Problem Description
Alice and Bob are playing a game. It is played in 1*N grids. Each grid can be occupied by one stone. Alice has K white stones on the left (numbered 1 to K from left to right), and Bob has K black stones on the right (numbered 1 to K from right to left). They take turns to move their own stones, and Alice moves first. In each move, the player must choose one stone to move to the nearest empty grid forward (Alice moves to the right, Bob moves to the left). If one player cannot find any stone to move, he wins.
Now Alice asks you to find a winning strategy of the game. Can you help him?
Now Alice asks you to find a winning strategy of the game. Can you help him?
Input
There are multiple test cases. In each case, there is one line containing two integers N, K.
Technical Specification
3 <= N <= 1,000,000, 1 < K*2 < N
Technical Specification
3 <= N <= 1,000,000, 1 < K*2 < N
Output
For each case, print in one line containing the case number (starting with 1) and the winning information. If Alice loses, just print “Bob”, otherwise print “Alice” and the first stone he chooses. If there are multiple stones he can choose, he will choose the rightmost one.
Sample Input
3 14 1
Sample Output
Case 1: BobCase 2: Alice 1
题目意思:
长度为N的格子,Alice和Bob各占了最左边以及最右边K个格子,每回合每人可以选择一个棋子往对面最近的一个空格移动。最先不能移动的人获得胜利。
分析:
k=1时
很容易看出,n为奇数则后手获胜,n为偶数则先手获胜
k>1时
如果n=2*k+1,则棋 盘中只有一个空白的格子,每次移动必须移动到当前的空白格子上。先手方可以先随意选择一颗棋子占据中间的位置,然后双方互有移动,移动过程中双方肯定都会 选择一颗在己方半场的棋子移动到对方半场里。直到后手方还剩下一颗己方半场的棋子时,先手方把占据中间的棋子移动到对方半场,此时后手方必须移动剩下的这 颗棋子到空出的中间的格子里,先手方再把最后一颗棋子移动到新空出的位置即可获胜。
如果n>2*k+1,那么棋盘中就有了多余一个的 空白格子。如果n为奇数,先手方只要每次移动己方最靠后的一颗棋子即可获胜。并且第一次移动必须选择1号棋子,否则会让自己的棋子中间留下空白相当于把先 手让给了对方,这时对方只要采用先手策略即可获胜;如果n为偶数,那么先手方只需采用n=2*k+1时的策略在双方交会的时候保住先手即可,当然此时的第 一步还是1号棋子,否则将失去先手优势。
代码:
#include<bits/stdc++.h>using namespace std;int main(){ int n,k,_case = 0; while(cin >> n >>k) { printf("Case %d: ",++_case); if(k == 1)printf(n%2?"Bob\n":"Alice 1\n"); else if( n == 2*k + 1) printf("Alice %d\n",k); else printf("Alice 1\n"); } return 0;}
0 0
- 博弈_______Stone Game(hdu 4387)
- 博弈_______Stone Game II(hdu 4388 2012多校第九场)
- HDU 4387 Stone Game 博弈
- hdu 4701 Game----博弈
- HDU 3389 Game (博弈)
- HDU 5011-Game(博弈)
- HDU-5011 Game 博弈
- hdu 5011 Game(博弈)
- [博弈] hdu 5011 Game
- hdu 3389 Game 博弈
- hdu 5011 Game 博弈
- HDU 5011-Game(博弈)
- HDU 5011 Game (博弈)
- hdu 1846 Brave Game(博弈)
- HDU 4023 Game (博弈)
- hdu 3951 博弈 Coin Game
- HDU 4023 Game 贪心 + 博弈
- HDU 1846 Brave Game 博弈
- android之文件存储路径问题
- 在TextView中添加超链接
- 【opencv的学习】播放avi视频和视频播放控制
- 认识CoreData-使用进阶
- STA 进程内Com组件剖析
- 博弈_______Stone Game(hdu 4387)
- linux进程编程(三)-- execl()函数使用
- 分布式系统MIT 6.824学习资源
- 158.You want to create a role to meet these requirements: 1: The role is to be protected from unauth
- Object类
- test
- 玲珑学院-1010-Alarm【打表】【找规律】【思维】
- 使用spring容器管理和配置netty
- C++中Polymorphism的实现