ZOJ3452 Doraemon's Stone Game

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值