結果

問題 No.159 刺さらないUSB
ユーザー testtest
提出日時 2020-09-16 16:31:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,085 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 198,468 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 17:12:30
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

double p, q;
void input() { cin >> p >> q; }

// よって(1-p)q<p(1-q)qならYESとなる
void solve() {
  cout << (((1.0 - p) * q) < p * (1.0 - q) * q ? "YES" : "NO") << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
  getchar();
}

// http://sugarknri.hatenablog.com/entry/2016/05/14/133550
// 確率の計算
// P1は「0回目で刺さらずかつ1回目で刺さる確率」なので
// 最初裏である確率(1-p)×1回ひっくり返して刺さる確率q
// P2は「0,1回目で刺さらずかつ2回目で刺さる確率」なので
// 最初表である確率p×最初刺さらない確率(1-q)×2回ひっくり返して刺さる確率q
// よって(1-p)q<p(1-q)qならYESとなる

// q≠0なので両辺qで割り
// 1-p<p-pq
// "p≠0なら"両辺pで割り
// 1/p+q<2
// となる
// ところで元の不等式はp=0のとき左辺=右辺=0なのでfalseであり、
// C言語では1/0.0はinfとなりinf<2はfalseなので、この時も最後の式で良い事がわかる
0