csu 1577 Dice Game (博弈)

题意:有两个人 每个人可以撒两个骰子 给出每个骰子的最大和最小值

        谁撒出的数值和大谁获胜 

思路: 把两个人可能的值区间算出 因为是均匀分布

        所以两人重叠的区间胜率相同 那么 只需计算谁获胜的区间大即可得出结果

 

#include<cstdio>

#include<iostream>

#include<cstring>

#include<cmath>

#include<queue>

#include<stack>

#include<vector>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int dir4[][2]={{0,1},{1,0},{0,-1},{-1,0}};

int dir8[][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};

int main()

{

    int a1,b1,a2,b2,A1,B1,A2,B2;

    while(scanf("%d%d%d%d%d%d%d%d",&a1,&b1,&a2,&b2,&A1,&B1,&A2,&B2)!=EOF)

    {

        int minn1=a1+a2,maxn1=b1+b2,minn2=A1+A2,maxn2=B1+B2;

        //printf("%d %d %d %d",minn1,maxn1,minn2,maxn2);

        if(maxn2<=minn1 || maxn1<=minn2)

        {

            //printf("1...\n");

            if(maxn2<=minn1) printf("Gunnar\n");

            else printf("Emma\n");

        }

        else if(minn1==minn2 && maxn1==maxn2)

        {

           // printf("2...\n");

            printf("Tie\n");

            //continue;

        }

        else if((minn2<=maxn1&&minn2>=minn1&&maxn2>=maxn1) || (minn1<=maxn2&&minn2<=minn1&&maxn1>=maxn2))

        {

            //printf("3...\n");

            if(minn2<=maxn1&&minn2>=minn1&&maxn2>=maxn1) printf("Emma\n");

            else printf("Gunnar\n");

        }

        else if((minn1>=minn2&&maxn2>=maxn1) || (minn2>=minn1&&maxn2<=maxn1))

        {

            //printf("%d %d %d %d",minn1,maxn1,minn2,maxn2);

            if(minn1>=minn2&&maxn2>=maxn1)

            {

                int len1=minn1-minn2;

                int len2=maxn2-maxn1;

                if(len2>len1) printf("Emma\n");

                else if(len1==len2) printf("Tie\n");

                else printf("Gunnar\n");

            }

            else

            {

                int len1=minn2-minn1;

                int len2=maxn1-maxn2;

                if(len2>len1) printf("Gunnar\n");

                else if(len1==len2) printf("Tie\n");

                else printf("Emma\n");

            }

        }

    }

    return 0;

}

  

你可能感兴趣的:(game)