2018年長沙理工大學第十三屆程序設計競賽 C 取手機 【概率】

鏈接:https://www.nowcoder.com/acm/contest/96/C
來源:牛客網

時間限制:C/C++ 1秒,其他語言2秒
空間限制:C/C++ 32768K,其他語言65536K
64bit IO Format: %lld
題目描述
durong有a臺iphonex和b臺s8,並且放在一個保險箱裏,durong現在一臺一臺從保險箱隨機拿出這些手機,現在他想知道第k次拿出s8的概率是多少
輸入描述:

第一行一個正整數T,表示數據組數。(1<=T<=10000)
接下來T行輸入a,b,k
其中(1<=a,b,k<=1e9) k<=a+b;

輸出描述:

第k次拿出s8的概率,保留三位小數

示例1
輸入

1
1 1 1

輸出

0.500

思路

我們可以假設 將 N 臺手機排序 然後一步一步從隊首取出

問題就轉變爲

排在第K位爲S8的概率是多少
那麼顯然答案就是 b / n

AC代碼

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric> 
#include <sstream>
#include <iomanip>
#include <limits>

#define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;

const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8;

const int INF = 0x3f3f3f3f;
const int maxn = 5e2 + 5;
const int MOD = 1e9;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int a, b, k;
        scanf("%d%d%d", &a, &b, &k);
        printf("%.3lf\n", b * 1.0 / (a + b));
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章