您的位置:首页 > 其它

ZOJ3452 Doraemon's Stone Game

2015-07-29 23:55 176 查看
Doraemon's Stone Game

Time Limit: 2 Seconds Memory Limit: 65536 KB

Doraemon is playing a game with Dorami. Initially there are piles of stones on the table. Each pile consists of at most 2 stones. Each stone may be black or white. Doraemon and Dorami
take turn to take away the stones, the rule is as follows:

Doraemon can only take away a white stone each time.
Dorami can only take away a black stone each time.
If the stone in the bottom is taken away, the whole pile is removed.
The first one who can't take away any stone lose. The other one is the winner

Now the piles of stones on the table are known, Doraemon wants to know if he can win. Can you help him?

Input

There are multiple cases (about 45000).

For each case, the first line is an integer N (1 ≤ N ≤ 6). Then N lines follows. The i-th line contains a string Si and an integer number ai (1 ≤ ai ≤ 1000000000). Si represents
a pile of stones. The characters from left to right correspond to stones from top to bottom. The character 'w' means that stone is white and 'b' means that stone is black. The integer ai means there are ai piles of stones
represented by Si. It's guaranteed that Si ≠ Sj when i ≠ j.

Output

For each case, output two words separated by a space in one line. The first word should be "win" if Doraemon can win the game if he makes move first, otherwise it should be "lose". The
second word should be "win" if Doraemon can win the game if Dorami makes move first, otherwise it should be "lose".

Sample Input

2
w 1
b 1
2
b 1
wb 1

Sample Output

lose win
lose lose


题意:Doraemon 和 Dorami一起玩游戏,Doraemon只能拿白色石子,Dorami只能拿黑色石子,两人轮流操作,如果谁没有石子拿了,那么谁就输了。输出如果Doraemon先拿和后拿两种情况下的结果。告诉n堆石子,每堆用si来表示,共有ai堆,每堆至多2个石子。序列从左到右表示石子从上到下,如果最下面一个被拿走了,那么上面的会消失。

思路:对于单个的情况,w可以支撑1回合,ww可以支撑2回合,所以对于人来说,怎么才算最优拿法,那就是尽量多拿混合类型。如果对方拿wb,那么我可以拿一个bw和他相互抵消,可以理解成,对方让我少了个w可以拿,那么我会让对方少一个b可以拿,使得整个优势不会出现偏移。相互抵消后,剩下的wb或者bw,假设剩下WB,对于A,B两个人来说,B可以拿所有的B,因为B不会自动减少,对于A来说,如果A先拿,那么A可以拿(n+1)/2次,如果A后拿,那么能拿n/2次。对于剩下BW的情况同理。所以最后,只用比较两人可以拿的总次数的大小即可。

#include <cstdio>
#include <cstring>
define LL long long

using namespace std;

int n;
char s[10];
LL t,co[6];

int main()
{
while(~scanf("%d",&n))
{
co[0]=co[1]=co[2]=co[3]=0;
while(n--)
{
scanf("%s%d",s,&t);
if(s[1]=='\0'||s[0]==s[1])
{
co[s[0]=='w'?0:1]+=(s[1]=='\0'?t:2*t);
}
else if(s[1]=='w')
{
co[2]+=t;
}
else
{
co[3]+=t;
}
co[4]=min(co[0],co[1]);
co[0]-=co[4];
co[1]-=co[4];
co[4]=min(co[2],co[3]);
co[2]-=co[4];
co[3]-=co[4];
}
printf("%s %s\n",co[0]+(co[2]+1)/2>co[1]+co[3]/2?"win":"lose",
co[0]+co[2]/2>=co[1]+(co[3]+1)/2?"win":"lose");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: