CodeForcesGym 100502D Dice Game

來源:互聯網
上載者:User

標籤:

Dice GameTime Limit: 1000msMemory Limit: 524288KBThis 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 ?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.

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

 

CodeForcesGym 100502D Dice Game

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.