CodeForcesGym 100502D Dice Game

Dice Game

Time Limit: 1000ms
Memory Limit: 524288KB
This problem will be judged on  CodeForcesGym. Original ID: 100502D
64-bit integer IO format: %I64d      Java class name: (Any)

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 finished 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.

Task

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.

Input

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

Output the name of the player that has higher probability of winning. Output “Tie” if both players have same probability of winning.

Sample Input 1                                                      Sample Output 1

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 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4461440.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值