Test instructions: There are two people each can sprinkle two dice to give the maximum and minimum value of each dice
Who spread out the numbers and the big who wins
Idea: Calculate the possible value intervals for two people because they are evenly distributed
So the two overlapping interval winning the same so just calculate who wins the interval large can produce results
#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 Minn 1=A1+A2,MAXN1=B1+B2,MINN2=A1+A2,MAXN2=B1+B2; printf ("%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", 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;}
CSU 1577 Dice Game (game)