Problem Statement |
|||||||||||||
|
Fox Ciel is playing a board game with her friend Squirrel Liss. The game is played on an infinite strip of paper. The strip of paper is divided into consecutive cells. Each cell has an integer coordinate. Formally, for each integer i, the left neighbor of cell i is cell (i-1) and the right neighbor of cell i is cell (i+1). |
||||||||||||
Definition |
|||||||||||||
|
|
||||||||||||
|
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- |
mov1 will be between 1 and 100,000,000, inclusive. |
||||||||||||
- |
mov2 will be between 1 and 100,000,000, inclusive. |
||||||||||||
- |
rng1 will be between 1 and 100,000,000, inclusive. |
||||||||||||
- |
rng2 will be between 1 and 100,000,000, inclusive. |
||||||||||||
- |
d will be between 1 and 100,000,000, inclusive. |
||||||||||||
Examples |
|||||||||||||
0) |
|
||||||||||||
|
|
||||||||||||
1) |
|
||||||||||||
|
|
||||||||||||
2) |
|
||||||||||||
|
|
||||||||||||
3) |
|
||||||||||||
|
|
||||||||||||
4) |
|
||||||||||||
|
|
||||||||||||
5) |
|
||||||||||||
|
|
||||||||||||
6) |
|
||||||||||||
|
|
||||||||||||
7) |
|
||||||||||||
|
|
||||||||||||
8) |
|
||||||||||||
|
|
类型:博弈 难度:2
题意:不知道为啥这道不算太难的博弈会是550分的题,考察细节吧。Ciel和Liss在一条直线的两点,相距距离为d,他们每次能走的最大距离为mov1,mov2,他们的武器能够到的范围为rng1,rng2,Ciel先走,每一步包括走一段并可以尝试用武器打对方,每个人都用最优策略走,问谁会赢,还是平局
分析:1、首先应该考虑第一回合会不会分出胜负,若mov1+rng1>=d,那么Ciel赢,若mov2+rng2>=d+mov1,Liss赢(Liss后手,要加mov1)
2、若第一回合分不出胜负,那么需要比较mov1,mov2(之前考虑比较mov1+rng1和mov2+rng2,发现并不正确,每次只能走mov步,所以要按mov来分情况)
(1)mov1==mov2,一定是平局
(2)mov1>mov2,Ciel走得快,那么Ciel如果想赢,必须在追着Liss走了x步时能打到Liss,但是又要防止Liss在x-1步时反向走倒打一耙,所以需要满足条件,
mov1-mov2+rng1>mov2+rng2。也可以理解为,当Ciel走到和Liss距离为mov1+rng1时,Liss又会走mov2,那么Ciel必须保证第x步走到和Liss距离为mov1-mov2+rng1,然后Liss走第x步走过mov2,然后这时轮到Ciel走第x+1步,此时距离为mov1+rng1,那么一走一打刚好打到Liss,其中,当Ciel走完第x步而Liss未走第x步时,二者距离最近,为mov1-mov2+rng1,必须保证这个距离大于mov2+rng2,否则Liss就会倒打一耙,就是平局。
(3)mov1<mov2,和(2)同理
代码:
#include<string> #include<cstdio> #include<vector> #include<cstring> #include<map> #include<iostream> #include<algorithm> #include<cmath> #include<set> using namespace std; class FoxAndFencing { public: string WhoCanWin(int mov1, int mov2, int rng1, int rng2, int d) { if(mov1+rng1>=d) return "Ciel"; else if(mov2+rng2>=mov1+d) return "Liss"; if(mov1>mov2) { if((mov1-mov2)+rng1 > mov2+rng2) return "Ciel"; return "Draw"; } if(mov1<mov2) { if((mov2-mov1)+rng2 > mov1+rng1) return "Liss"; return "Draw"; } return "Draw"; } }; int main() { FoxAndFencing t; cout << t.WhoCanWin(2,1,1,100,50)<<endl; }