結果

問題 No.2461 一点張り
ユーザー arimakishou0505arimakishou0505
提出日時 2023-09-10 01:50:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,211 bytes
コンパイル時間 3,911 ms
コンパイル使用メモリ 229,464 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 01:50:42
合計ジャッジ時間 4,824 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 21 ms
4,380 KB
testcase_02 AC 21 ms
4,376 KB
testcase_03 AC 37 ms
4,384 KB
testcase_04 AC 20 ms
4,376 KB
testcase_05 AC 31 ms
4,376 KB
testcase_06 AC 21 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>
#include<atcoder/all>


#define rep(i,n)for(ll i=0;i<n;i++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define prique priority_queue<int, vector<int>, greater<int> > 

using ll = long long;
using ull = unsigned long long;

ll mod = 998244353;
ll modi = 499122177;
const int inf = 1000000000;

using namespace std;
using namespace atcoder;







vector<ll> topological_sort(vector<vector<ll>>& G, vector<ll>& indegree) {
    ll n = G.size();
    vector<ll> res;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for (ll i = 1; i < n; i++) if (indegree[i] == 0) que.push(i);
    while (!que.empty()) {
        ll ver = que.top();
        que.pop();
        res.push_back(ver);
        for (int i : G[ver]) {
            indegree[i]--;
            if (indegree[i] == 0) que.push(i);
        }
    }
    return res;
}

ll gcd(ll a, ll b) {

    if (a > b)swap(a, b);
    while (a > 0) {
        b %= a;
        if (a > b)swap(a, b);
        if (a == b)break;
    }
    return b;
}





bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


bool ing(ll x, ll y, ll h, ll w) {
    bool a = x < h && y < w;
    bool b = x >= 0 && y >= 0;
    return a && b;
}



void dfs(vector<ll>& vis, vector<vector<ll>>& G, ll x) {

    vis[x] = 1;
    for (ll i : G[x]) {
        if (vis[i] == 0) {
            dfs(vis, G, i);
        }
    }
}


int main() {
    ll t;
    cin >> t;
    while (t--) {
        ll  k;
        double p;
        cin >> p >> k;

        double ans = 0;
        double j = 1;

        for (ll i = 1; i < k; i++) {
            double a = pow(1 - p, i - 1) * p;
           
            j-= a;
            ans += a * i;
        }
        ans += j * k;
        cout <<fixed<< setprecision(10);
        cout  <<ans << endl;
    }
}
0