• 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
  • 相关阅读:
    如何在EXCEL SHEET中 动态添加控件
    和菜鸟一起学OK6410之ADC模块
    和菜鸟一起学证券投资之消费物价指数CPI
    和菜鸟一起学证券投资之股市常见概念公式2
    作为软件工程师,你必须知道的20个常识
    和菜鸟一起学c++之虚函数
    和菜鸟一起学单片机之入门级led流水灯
    在国内各大软件下载网站上,“万能数据库查询分析器”已更新至 2.02 版本
    和菜鸟一起学证券投资之股市简单财务分析
    和菜鸟一起学OK6410之蜂鸣器buzzer字符驱动
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4461440.html
Copyright © 2020-2023  润新知