标签:
Gunnar and Emma play a lot of board games at home, so they own many dice that are not normal 6sided dice. For example they own a die that has 10 sides
with numbers 47,48,...,56 on it.
TherehasbeenabigstorminStockholm,soGunnar and Emma have been stuck at home without electricity for a couple of hours. They have ?nished playing all the games they have, so they came up with a new one. Eachplayerhas2dicewhichheorsherolls. Theplayer with a bigger sum wins. If both sums are the same, the game ends in a tie.
Given the description of Gunnar’s and Emma’s dice, which player has higher chances of winning?
All of their dice have the following property: each die contains numbers a,a +1,...,b, where a and b are the lowest and highest numbers respectively on the die. Each number appears exactly on one side, so the die has b − a +1 sides.
The first line contains four integers a1,b1,a2,b2 that describe Gunnar’s dice. Die number i contains numbers ai,ai +1,...,bi on its sides. You may assume that 1 ≤ ai ≤ bi ≤ 100. You can further assume that each die has at least four sides, so ai +3 ≤ bi.
The second line contains the description of Emma’s dice in the same format.
Output the name of the player that has higher probability of winning. Output “Tie” if both players have same probability of winning.
1 4 1 4 1 6 1 6 |
Emma |
Sample Input 2 |
Sample Output 2 |
1 8 1 8 1 10 2 5 |
Tie |
Sample Input 3 |
Sample Output 3 |
2 5 2 7 1 5 2 5 |
Gunnar |
NCPC 2014 Problem D: Dice Game
解题:直接暴力搞
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[4],b[4],A[10010],B[10010],totA,totB; 4 void solve(int a1,int b1,int a2,int b2,int *o,int &tot) { 5 for(int i = a1; i <= b1; ++i) 6 for(int j = a2; j <= b2; ++j) 7 o[tot++] = i + j; 8 } 9 int main() { 10 while(~scanf("%d %d %d %d",a,b,a+1,b+1)) { 11 scanf("%d %d %d %d",a+2,b+2,a+3,b+3); 12 totA = totB = 0; 13 solve(a[0],b[0],a[1],b[1],A,totA); 14 solve(a[2],b[2],a[3],b[3],B,totB); 15 sort(A,A+totA); 16 sort(B,B+totB); 17 int sumA = 0,sumB = 0,i = 0,j = 0; 18 while(i < totA && j < totB){ 19 if(A[i] < B[j]){ 20 sumB += totB - j; 21 i++; 22 }else j++; 23 } 24 i = j = 0; 25 while(i < totA && j < totB){ 26 if(B[j] < A[i]){ 27 sumA += totA - i; 28 j++; 29 }else i++; 30 } 31 if(sumA == sumB) puts("Tie"); 32 else if(sumA > sumB) puts("Gunnar"); 33 else puts("Emma"); 34 } 35 return 0; 36 }
CodeForcesGym 100502D Dice Game
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4461440.html