比赛链接
概率 贪心 思维
题意:
红蓝两色的球分别有n,m个,一共k瓶子,保证没有空瓶子和没放入瓶子的球,问拿到蓝色球的最大概率
思路:
总概率=每个瓶子概率/k 所以尽可能多的使每个瓶子概率最大。可以想到最大概率就是全是蓝球,概率为1。所以判断m和k大小,如果m>k,那么放完所有瓶子后还剩蓝球概率就为
p=(m-k+1)/(n+m-k+1)
如果m<k那么只能放n个瓶子中
#define _CRT_SECURE_NO_WARNINGS 1;
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#define ll long long
#define off ios::sync_with_stdio(false);
#define INF 0x3f3f3f3f
const int N = 300 + 10;
using namespace std;
int p[N][N];
int main()
{
off;
int n, m, k;
cin >> n >> m >> k;
if (m < k) {
printf("%.6lf",(1.00 * m / k));
}
else {
printf("%.6lf", (1.00 * (m - k + 1) / (n + m - k + 1) + (k - 1)) / k);
}
return 0;
}
二分
题意
做汉堡,汉堡由B,S,C组成,给出现有的B,S,C的数量和价格,再给出总金额,问能做最多多少个汉堡
思路
设置金额从INF开始二分做的汉堡数量,判断此时做的汉堡所需的总金额是否大于给的钱数
#define _CRT_SECURE_NO_WARNINGS 1;
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#define ll long long
#define off ios::sync_with_stdio(false);
#define INF 0x3f3f3f3f
using namespace std;
const ll N = 2000000000000;
ll nb, nc, ns;
ll b, c, s;
ll pb, ps, pc;
ll sum;
bool judge(ll n) {
ll bb, cc, ss;
bb = (n * b - nb) * pb;
cc = (n * c - nc) * pc;
ss = (n * s - ns) * ps;
if (bb < 0) bb = 0;
if (cc < 0) cc = 0;
if (ss < 0) ss = 0;
if (bb + cc + ss > sum) return false;
else return true;
}
int main()
{
off;
string a;
cin >> a >> nb >> ns >> nc >> pb >> ps >> pc >> sum;
for (int i = 0; i < a.size(); i++) {
if (a[i] == 'B') b++;
else if (a[i] == 'C') c++;
else s++;
}
ll l = 1;
ll r = N;
while (l < r) {
ll mid = (l + r) >> 1;
if (judge(mid) == true)
l = mid + 1;
else
r = mid;
}
cout << l - 1 << endl;
return 0;
}