문제
The popular streaming platform switch.tv just unveiled their newest feature: switch betting. Streamers can now get their viewers to bet on two different options using switch points (patented).
Each viewer bets some number of switch points for one of the two options. The total amount of switch points bet by everyone is called the prize pool. The streamer will choose one of the options as the winner and the prize pool is split (not necessarily equally) between all the viewers who bet on that option; the more you bet on the option, the more of the prize pool you receive. In particular, if you contributed p% of all the bets for one of the options and that option wins, then you receive p% of the total prize pool.
The switch.tv team has come to you to compute what the switch point payout is for each viewer if their selected option wins. To do this, they ask you to find the switch-payout-ratio for each of the two options. Since the payout to each viewer is proportional to the number of switch points they put into the bet, the switch team will be able to use this ratio to determine each viewer's winnings.
For example, suppose a streamer created a switch bet where three viewers participated. Two viewers bet 10 and 30 switch points on option one and the last viewer bets 10 switch points on option two. We can see that option one has 80 of the bets and option two has 20 of the bets.
If option one wins, then the two viewers who bet on that receive 12.5 and 37.5 switch points, respectively, which means that the switch-payout-ratio is 1:1.25 for option one. If option two wins, then the single viewer who bets on that receives 50 switch points, which means that the switch-payout-ratio is 1:5.
Given the percentage of total bets for option one, help switch.tv by computing the switch-payout-ratio for the two options.
입력
The input consists of one integer (), which is the percentage of switch points bet on option one.
출력
For each option (option one, then option two), display the number x such that 1:x is the switch-payout-ratio for that option. Your answer should have an absolute or relative error of at most 10^-3.
풀이
베팅을 할 경우 각 옵션에 따른 배당금을 출력해야 하는 문제였다.
다행히 A 또는 B의 두가지 옵션밖에 없기 때문에 각각 받을 수 있는 배당금에 대해 구하면 되는 문제로
입력값은 첫 번째 옵션을 선택한 사람의 비율이다.
비율이 높으면 높을수록 1에 가깝기 때문에 100/비율을 통해 A 옵션의 배당금을 구할 수 있고
B 옵션의 비율은 100 - A 옵션의 비율(입력된 값)이기 때문에 100 / (100 - A옵션)을 통해 B 옵션의 배당금을 구할 수 있다.
각 값을 출력해 문제를 해결할 수 있다.
const input = Number(require('fs').readFileSync('/dev/stdin').toString().trim())
console.log(100/input)
console.log(100/(100-input))
const input = Number(`80`)
console.log(100/input)
console.log(100/(100-input))'알고리즘 > 백준' 카테고리의 다른 글
| [백준 JS] 1247번 부호 (0) | 2023.03.13 |
|---|---|
| [백준 JS] 1085번 직사각형에서 탈출 (0) | 2023.03.09 |
| [백준 JS] 15552번 빠른 A+B (0) | 2023.03.09 |
| [백준 JS] 11945번 뜨거운 붕어빵 (0) | 2023.03.09 |
| [백준 JS] 11720번 숫자의 합 (0) | 2023.03.09 |
