ABC126-C : Dice and Coin

Dice and Coin

https://atcoder.jp/contests/abc126/tasks/abc126_c

  • 문제 자체는 걍 쉬움. 기억해야될 교훈은 cout은 실수표현을 제대로 못해준다는거. 6자리에서 잘라먹는다.
  • printf를 활용해서 충분히 길게 format을 주어야 함
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cstdio>
using namespace std;
 
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  
  int doubled = 1;
  double prob = 1;
  double ans = 0;
  for(int i = N; i > 0; i--) {
    while(i*doubled < K)
      doubled *= 2, prob /= 2;
    ans += prob / N;
  }
}