fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 31490 (C++) Throwing dice
최초 업로드: 2025-11-01 07:26:24
최근 수정 시간: 2025-11-01 07:26:24
게시자: rlatjwls3333
카테고리: 백준
조회수: 12
# [Silver II] Throwing dice [문제 링크](https://www.acmicpc.net/problem/31490) ## 문제 설명 <p>Alice and Bob are discussing penalty shoot-outs and their randomness: “We might as well be throwing dice to determine the winner!”, Alice said. And so they started simulating penalty shoot-outs by each throwing dice, summing the points indicated on their dice, and comparing these sums. The player with the largest sum wins; in case both sums are equal, there is a tie.</p> <p>But even in such situations, some player might have an edge over their opponent, depending on which dice they throw. Thus, just by looking at the dice they are about to throw, Alice and Bob want to determine who has the better edge.</p> <p>Alice has $M$ fair dice, with $A_1, A_2, \dots , A_M$ sides. For all integers $k$ and $\ell$ such that $1 \le k \le M$ and $1 \le \ell \le A_k$, the $k$<sup>th</sup> die of Alice has a probability $1/A_k$ of showing its face numbered $\ell$. Then, Alice’s score is the sum of the numbers displayed by her $M$ dice. Similarly, Bob has $N$ fair dice, with $B_1, B_2, \dots , B_N$ sides.</p> <p>Given these dice, Alice has a probability $\mathbb{P}_A$ of having a strictly larger score than Bob, and Bob has a probability $\mathbb{P}_B$ of having a strictly larger score than Alice. Which probability is the largest one?</p> ## 입력 <p>The input consists of three lines, each one containing space-separated integers. The first line contains the numbers $M$ and $N$. The second line contains the numbers $A_1, A_2, \dots , A_M$. The third line contains the numbers $B_1, B_2, \dots , B_N$.</p> ## 출력 <p>The output should contain a single line, consisting of a single uppercase word: <code>ALICE</code> if $\mathbb{P}_A > \mathbb{P}_B$, <code>TIED</code> if $\mathbb{P}_A = \mathbb{P}_B$, and <code>BOB</code> if $\mathbb{P}_A < \mathbb{P}_B$.</p> ## 풀이 A가 뽑을 기댓값과 B가 뽑을 기댓값을 비교하여 풀 수 있습니다. A의 기댓값은 각 카드 $A_i$의 기댓값의 합이고 $A_i$의 기댓값은 $A_i * (A_i+1) / (2 * A_i) = (A_i+1)/2$입니다. 따라서 A의 기댓값은 $A_i$의 합 + N으로 나타낼 수 있습니다. ``` c++ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; ll sum1=n, sum2=m; while(n--) { ll a; cin >> a; sum1 += a; } while(m--) { ll b; cin >> b; sum2 += b; } if(sum1>sum2) cout << "ALICE"; else if(sum2>sum1) cout << "BOB"; else cout << "TIED"; } ```