https://www.acmicpc.net/problem/20170
๋ฌธ์
Since the year 2000, an ICPC regional contest has been held every year in Korea. To commemorate the 21st regional contest this year, it is decided to make a dice. The commemorative dice is a regular cube with a positive number written on each of its sides like an ordinary dice; however, the six numbers are not necessarily to be 1, 2, 3, 4, 5, 6 but just their sum is 21.
The dice can be used in various ways. For example, two people can play a game as follows: Each of the two picks one out of the many dice and then rolls the dice. The winner is the one who tosses a bigger number. It is important which dice to choose in this game because once the dice are set, the probability of one winning against the other is determined. Suppose that KyungYong chooses the dice shown in the figure below left and TaeCheon chooses the dice shown in the figure below right. Then, KyungYong wins when and only when TaeCheon tosses number 1, so the probability that KyungYong wins is 2/3.
Given the dice of the first and second players, write a program to calculate the probability of the first player winning.
์ ๋ ฅ
Your program is to read from standard input. The input consists of two lines. The first line contains six positive integers that are written on the sides of the dice of the first player. Also, the second line contains six positive integers that are written on the sides of the dice of the second player. The six integers given in a line add up to 21 and are separated by a single space.
์ถ๋ ฅ
Your program is to write to standard output. Print exactly one line that contains an irreducible fraction representing the probability of the first player winning. A fraction should consist of a numerator displayed before a slash and a non-zero denominator displayed after the slash. There are no spaces either before or after the slash. Note that an irreducible fraction refers to a fraction in which the numerator and denominator are integers that have no other common divisors than 1.
ํ์ด
์ฃผ์ฌ์ ๋์ ํ๋์ฉ ๋น๊ตํด์ ์ด๊ธฐ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๋ค
..๊น์ง์ ํ์ด๋ ๊ฐ๋จํ๋ค. ..ํ์ง๋ง
์ฌ์ค ์ด ๋ฌธ์ ์ ํฌ์ธํธ๋ c++๋ก ๊ธฐ์ฝ๋ถ์๋ฅผ ์ด๋ป๊ฒ ๋ง๋๋๋..!!
์ด ๋ฌธ์ ์์๋ ๋ถ๋ชจ๊ฐ 36์ผ๋ก ๊ณ ์ ๋์ด ์๊ธฐ ๋๋ฌธ์ ํ๊ฒฐ ํธํ๋ค
36์ ์ฝ์์ค ํฐ ๊ฒ๋ถํฐ ์ด๊ธด ์ w ๋ฅผ ๋๋์ด ๋จ์ด๋จ๋ฆฌ๋์ง ํ์ธํ๊ณ ,
๋๋์ด ๋จ์ด์ง๋ค๋ฉด 36๊ณผ w๋ฅผ ๋ ๋ค ํด๋น ๊ณต์ฝ์๋ก ๋๋ ์ ๊ฐ๊ฐ ์ต์ข ๋ถ๋ชจ์ ๋ถ์๋ก ์ด๋ค
#include <iostream>
using namespace std;
int main () {
//์
๋ ฅ
int a[6], b[6];
for(int i=0; i<6; i++){
cin >> a[i];
}
for(int i=0; i<6; i++){
cin >> b[i];
}
//์ฐ์นํ๋ ๊ฒฝ์ฐ์ ์ ๊ณ์ฐ
int win=0;
for(int i=0; i<6; i++){
for(int j=0; j<6; j++){
if(a[i] > b[j])
win++;
}
}
//๊ธฐ์ฝ๋ถ์ ๋ง๋ค๊ธฐ
int m = 36;
int arr[] = {36,18,12,9,6,4,3,2};
for(int i=1; i<8; i++){
if(win%arr[i] == 0) {
win /= arr[i];
m /= arr[i];
break;
}
}
//์ถ๋ ฅ
cout << win << "/" << m;
}
'๐ฆ Chango > ๐ฃ EDOC' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ][C++] ๋ฐฑ์ค 9946๋ฒ : ๋จ์ด ํผ์ฆ (0) | 2021.10.18 |
---|---|
[BOJ][C++] ๋ฐฑ์ค 17521๋ฒ : Byte Coin (0) | 2021.10.06 |
BOJ ๋ฐฑ์ค 16283๋ฒ : Farm (0) | 2021.09.29 |
[์๊ฐ][BOJ][C++] ๋ฐฑ์ค 20044๋ฒ: Project Teams (0) | 2021.09.29 |
[๊ตฌ๋ฆ][C++] 14ํ E-PPER 7๋ฒ : ์ ๋ฌธ๊ธฐ์ฌ (0) | 2021.09.27 |