hdu3544 (chocolate cut issue)

Links: http://acm.hdu.edu.cn/showproblem.php?pid=3544

To an n * m chocolate, Alice only vertical earnestly to A * m and B * m, and (A + B = n), Bob can only cut the vertical and n * A n * B, qie (A + B = m) (who can not be operated even if lost)

After the latter will try to cut the front which is selected from a small to cut, the upper hand shall try to take the middle cut.

Cutting contribution is based on Alice's positive contribution to the Bob's value is negative;

Points of discussion:

1, if only n * 1 of Alice Advantageously, only 1 * m advantageous to Bob.

2, if the chocolate 2 * 2 (this is a bug, no one was willing to cut) (equivalent to who should cut white two opportunities to each other, (your product, you fine chemicals)

3,2 * 3,3 * 2 Similarly to be abandoned;

4, if n * 2, Alice certainly find ways to cut more than several times, Bob will not go cut (note 1 * 2 can not cut this to Bob favorable, then cut each time 2 * 2, has a number of (n / 2 ) -1), 2 * m and vice versa;

5, the n * 3,3 * m, ...... are the same

Code:

#include<bits/stdc++.h>
#define ll long long
const int maxn=200020;
const int inf=-0x3f3f3f;
using namespace std;

ll gcd(int a,int b){return b==0?a:gcd(b,a%b);}
ll lcm(int a,int b){return gcd(a,b)/a*b;}
int fa1[maxn],fa2[maxn];
int n1,m1,n2,m2;

void solve(int k)
{
    int n;
    scanf("%d",&n);
    ll a=0,b=0;
    for(int i=1; i<=n; i++)
    {
        ll x,y;
        scanf("%lld%lld",&x,&y);
        while(x>1&&y>1) //让其变成4的那种形式
          {x>>=1; y>>=1;}
        if(y==1) a+=x-1;//能切x-1刀
        if(x==1) b-=y-1;// y-1 knife can cut 
    }
    printf("Case %d: %s\n", k, a+b>0? "Alice" : "Bob");
    return ;
}

int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1; i<=t; i++)
     solve(i);
    return 0;}

 

Guess you like

Origin www.cnblogs.com/sweetlittlebaby/p/12642738.html
cut