poj2931 Procrastination----不平等博弈

Procrastination
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 455 Accepted: 98

Description

Once upon a time, there were two graduate students that were best friends. During their short breaks from research (usually, not longer than several hours), the two students liked to play the game of Procrastination.

The game of Procrastination is for two players (black and white), who take turns moving. The game involves removing cubes from towers. Each cube is either black or white. At the start of the game, these cubes are arranged into 4 towers: each tower is a stack of several cubes. On a player’s turn, he can remove any cube that matches his color (the white player removes only white cubes, and the black player only removes black cubes). All the cubes above the chosen cube are also removed from the tower, irrespective of color. For example, suppose a tower is composed of the following cubes (from bottom to top): black, white, black, white. Then, if black removes the bottom-most black cube, he removes the entire tower, black can also take the 3rd cube, removing the 4th cube with it. If white removes the 2nd cube, then only one black cube will remain, white can also take the 4th cube. If a player cannot remove any cubes, he loses.

Having already been trained in the intricacies of the game during their undergraduate years, the two students learned to play the game perfectly, i.e., if a player had a winning strategy, then that player would win the game. However, at some time, they discovered that, for most starting configurations, one of the players has the winning strategy irrespective of which player moves first. They called a configuration a W-configuration if white has a winning strategy irrespective of who moves first, and a B-configuration if black has a winning strategy irrespective of who moves first.

Moreover, the friends noted that some partial configurations are at least as favorable for one player as other configurations. A partial configuration C is defined as a set of 3 towers, note that a partial configuration C together with a 4th tower T forms a complete game configuration, which we denote as (C, T). A formal definition of the notion “at least as favorable”, is as follows. A partial configuration C1 (composed of 3 towers) is at least as favorable for white as another partial configuration C2 (also composed of 3 towers) if and only if for any 4th tower T, if (C2, T) is a W-configuration then (C1, T) is also a W-configuration. In other words, there does not exist a 4th tower T such that (C1, T) is not a W-configuration and (C2, T) is a W-configuration.

Given two partial configurations C1 and C2, you are to check whether C1 is at least as favorable for white as the partial configuration C2.

Input

The first line of the input contains an integer, the number of test cases. A test case includes one line with Test N, where N is the current test case number followed by eight lines, specifying the two partial configurations C1 and C2 in this order. Each configuration is specified by four lines.

The first line of the partial configuration contains three numbers: n1, n2, n3 denoting the heights of the three towers of the partial configuration (0 ≤ n1, n2, n3 ≤ 50). The second line contains n1 letters (B or W) separated by spaces describing the first tower. The third line contains n2 letters separated by spaces describing the second tower. The fourth line contains n3 letters separated by spaces describing the third tower. A letter W denotes a white cube and the letter B denotes a black cube. Each tower is described in the bottom-to-top order.

Output

For each test case, print on a separate line the test case number and Yes if C1 is at least as favorable for white as the partial configuration C2, and No otherwise.

Sample Input

2
Test 1
3 3 1
W B B
W B W
B
3 3 3
B W W
B W W
W B B
Test 2
3 3 2
W B B
W B W
B B
3 3 3
B W W
B W W
W B B

Sample Output

Test 1: Yes
Test 2: No

Source

 
 
考虑精度问题
看论文!
#include<iostream>
#include<cstdlib>
#include<stdio.h>
using namespace std;
int tt[55];
long long  dfs(int n)
{
    long long  x=0,k=1;
    int i=1;
    k<<=52;//先乘上一个数
    while(i<=n&&tt[i]==tt[1])
    {
        if(tt[i]==1)
        x+=k;
        else x-=k;
        i++;
    }
    k>>=1;
    while(i<=n)
    {
        if(tt[i]==1)
        x=x+k;
        else x=x-k;
        i++;
        k>>=1;
    }
    return x;
}
void solve(int n)
{
     for(int i=1;i<=n;i++)
    {
            char c;
            cin>>c;
            if(c=='W') tt[i]=1;
            else tt[i]=0;

    }

}
int main()
{
    int t,d;
    char str[10];
    int a[55];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s%d",str,&d);
        char c;
        int n1,n2,n3;
        //cout<<str<<" "<<d<<endl;
        scanf("%d%d%d",&n1,&n2,&n3);
        long long ans1=0,ans2=0;
        solve(n1);ans1+=dfs(n1);
        solve(n2);ans1+=dfs(n2);
        solve(n3);ans1+=dfs(n3);
        scanf("%d%d%d",&n1,&n2,&n3);
        solve(n1);ans2+=dfs(n1);
        solve(n2);ans2+=dfs(n2);
        solve(n3);ans2+=dfs(n3);
        printf("%s %d: ",str,d);
     //  cout<<ans1<<" "<<ans2<<endl;
        if(ans1>=ans2) puts("Yes");
        else puts("No");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值