【无标题】Marbles Lucky Distribution 概率 贪心 && 基础算法

比赛链接

概率 贪心 思维

题意:

红蓝两色的球分别有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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值