码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 4336 Card Collector——最值反演

时间:2019-01-15 21:33:12      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:cstring   pac   就是   str   ==   期望   collect   http   scanf   

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336

点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max ;全部出现的期望就是最晚出现的元素的期望。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define db double
using namespace std;
const int N=25,M=(1<<20)+5;
int n,ct[M],bin[N];db p[N],g[M];
void init()
{
  int n=20;
  bin[0]=1;for(int i=1;i<=n;i++)bin[i]=bin[i-1]<<1;
  for(int s=1;s<bin[n];s++)ct[s]=ct[s-(s&-s)]+1;
}
int main()
{
  init();
  while(scanf("%d",&n)==1)
    {
      for(int i=1;i<=n;i++)scanf("%lf",&p[i]);
      for(int s=1;s<bin[n];s++)
    {
      g[s]=0;
      for(int i=1;i<=n;i++)if(s&bin[i-1])g[s]+=p[i];
      g[s]=1/g[s];
    }
      db ans=0;
      for(int s=1;s<bin[n];s++)
    ans+=(ct[s]&1?1:-1)*g[s];
      printf("%.10f\n",ans);
    }
}

 

hdu 4336 Card Collector——最值反演

标签:cstring   pac   就是   str   ==   期望   collect   http   scanf   

原文地址:https://www.cnblogs.com/Narh/p/10274306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!