当前位置:网站首页>2021 Niuke multi school training camp 5 (question b)
2021 Niuke multi school training camp 5 (question b)
2022-07-27 05:30:00 【Yuzhibo one dozen seven~】
B:Boxes



The question :
Yes n Boxes , Each box will have a ball , The color of the ball is black or white , The probability of each color is 1/2, The only way to see the ball in the box is to open the box , Open the first i The cost of a box is wi, You can also ask God once , God will tell you how many black balls there are in the remaining box , The cost of asking is C, Ask what is the minimum expected value of the cost of determining the color of the ball in all boxes
analysis :
There are two situations , One is to ask God , One is not asking God , If you don't ask God, it must be n All boxes are open , The answer is sum[n], Represents the former n Sum of weights , If you ask God, there is n In this case , The answer of God is different , this n The states of the boxes are 2^n Kind of , First, sort according to the unpacking weight from small to large , Then unpack in this order , If you drive to a position, you already know that the boxes behind are all 1 Or all 0 After that, it means success , We can write it as n = 3 The results are as follows :
3 Box status The weight of unpacking and
0 0 0 0
0 0 1 w1+w2
0 1 0 w1+w2
0 1 1 w1
1 0 0 w1
1 0 1 w1+w2
1 1 0 w1+w2
1 1 1 0
Just look at the position of the dividing line , Altogether i A place , The first i The weight of each position should be added 2^i Times (sum[i]), The probability of each case is
1/2^n, So the answer adds up to 
Finally, don't forget to take a minimum value without asking God . Now let's look at the code
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=1e5+10;
double w[N];
double sum[N];
int main()
{
int n;
double c;
cin>>n>>c;
for(int i=1;i<=n;i++)
scanf("%lf",&w[i]);
sort(w+1,w+n+1);// Sort the costs from small to large
for(int i=1;i<=n;i++)
sum[i]=sum[i-1]+w[i];
double ans=c;
double t=0.5;
for(int i=n-1;i>=1;i--)
ans+=t*sum[i],t/=2;
if(ans>sum[n]) ans=sum[n];
printf("%.10lf",ans);
return 0;
}
边栏推荐
猜你喜欢

Idea remote debugging

MQ set expiration time, priority, dead letter queue, delay queue

JVM Part 1: memory and garbage collection part 12 -- stringtable

Graph cuts learning

Multiplication sorting in torch, * & torch. Mul () & torch. MV () & torch. Mm () & torch. Dot () & @ & torch. Mutmal ()

BIO、NIO、AIO区别

flask项目配置

How to quickly and effectively solve the problem of database connection failure

JVM Part 1: memory and garbage collection part 9 - runtime data area - object instantiation, memory layout and access location

Redis cluster
随机推荐
Find the number of combinations (the strongest optimization)
Carmaker quick start lesson 4 developing 48V P1 hybrid system
Notes series k8s orchestration MySQL container - stateful container creation process
B1031 check ID card
mq设置过期时间、优先级、死信队列、延迟队列
268.missing number of leetcode
numpy 数据类型转化
redis发布订阅模式
Scientific Computing Library - numpy
弹球小游戏
The concept of cloud native application and 15 characteristics of cloud native application
自己动手做一个爬虫项目
Message reliability processing
后台用户管理展示添加功能实现
Li Hongyi machine learning team learning punch in activity day05 --- skills of network design
消息可靠性处理
Flask请求数据获取与响应
Prime number screening (Ehrlich sieve method, interval sieve method, Euler sieve method)
封装JWT
B1030 perfect sequence