zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    基于html2canvas实现网页保存为图片及图片清晰度优化
    玩转 React(四)- 创造一个新的 HTML 标签
    浅谈前后端分离与实践(一)
    javascript新手实例1-DOM基本操作
    一个看一次就永远不会忘的windows环境开发小技巧
    细说Web API中的Blob
    所见即所得,实现一个有趣的动画效果
    带你玩转prefetch, preload, dns-prefetch,defer和async
    Hologres+Flink流批一体首次落地4982亿背后的营销分析大屏
    浏览器报错:ERR_PROXY_CONNECTION_FAILED的解决方法
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4461440.html
Copyright © 2011-2022 走看看