首页 > 其他 > 详细

概率与期望

时间:2018-04-22 15:51:07      阅读:145      评论:0      收藏:0      [点我收藏+]

https://vjudge.net/problem/LightOJ-1030

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
 int t;
 cin>>t;
 int a[110];
 double dp[110];
 for(int i=1;i<=t;i++)
 {
  memset(a,0,sizeof(a));
  memset(dp,0,sizeof(dp));
  dp[1]=1;
  int n,h;
  double ans=0;
  cin>>n;
  for(int j=1;j<=n;j++)
  cin>>a[j];
  for(int j=1;j<=n;j++){
   if(n-j<6)
   h=n-j;
   else
   h=6;
   for(int k=1;k<=h;k++)
   {
    dp[j+k]+=dp[j]*1.0*1/h;
   }
   ans+=1.0*a[j]*dp[j];
  }
  printf("Case %d: %lf\n",i,ans);
 }
 return 0;
}

 

 

https://vjudge.net/problem/LightOJ-1027

#include<iostream>
using namespace std;
int gcd(int a,int b)
{
return b>0?gcd(b,a%b):a;
}
int main()
{
int t;
int a[110];
cin>>t;
for(int i=1;i<=t;i++)
{
int n,sum1=0,sum2=0,door1=0,door2=0;
cin>>n;
for(int j=0;j<n;j++)
{
cin>>a[j];
if(a[j]>0)
{
sum1+=a[j];
door1++;
}
else
{
sum2+=-a[j];
door2++;
}
}
int q=gcd(sum1+sum2,n-door2);
cout<<"Case "<<i<<‘:‘<<‘ ‘;
if(door2==n)
cout<<"inf"<<endl;
else
cout<<(sum1+sum2)/q<<‘/‘<<(n-door2)/q<<endl;
}
return 0;
}

概率与期望

原文:https://www.cnblogs.com/caijiaming/p/8907365.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!