|
发表于 2009-12-18 20:20:00
|
显示全部楼层
Re:一个概率题,大家来算下……
程序新手,写的乱七八糟多见谅……
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;
int he1 (int a,int b,int c,int d)
{
int x;
if(a>b)
x=b;
else
x=a;
if(x>c)
x=c;
else if(x>d)
x=d;
else
x=x;
x=a+b+c+d-x;
return x;
}
int he2 (int a,int b,int c,int d,int e,int f,int g)
{
int x;
if(a>b)
x=b;
else
x=a;
if(x>c)
x=c;
else if(x>d)
x=d;
else if(x>e)
x=e;
else if(x>f)
x=f;
else if(x>g)
x=g;
else
x=x;
x=a+b+c+d+e+f+g-x;
return x;
}
int main (void)
{
srand(unsigned(time(NULL)));
int sum,a1,a2,a3,a4,i,j,h,x,y,z1,z2;
sum=y=0;
int b[7]={0,0,0,0,0,0,0};
int c[16]={0,0,0,0,0,0,1,2,3,4,5,6,8,10,13,16};
cout<<"请输入测试次数"<<endl;
cin>>z1;
cout<<"请输入要统计的购点数值,如要统计20以下不包含20,就输入20"<<endl;
cin>>z2;
for(h=1;h<=z1;h++)
{
j=0;
for(i=1;i<=6;i++)
{
a1=1+rand() % 6;
a2=1+rand() % 6;
a3=1+rand() % 6;
a4=1+rand() % 6;
x=he1(a1,a2,a3,a4);
x=c[x-3];
b[j]=x;
j++;
}
x=he2(b[1],b[2],b[3],b[4],b[5],b[6],b[0]);
sum=sum+x;
if(x<z2)
y++;
else
y=y;
}
cout<<"测试"<<h-1<<"次"<<endl;
cout<<"共消耗购点"<<sum<<endl;
cout<<z2<<"点以下的有"<<y<<"次"<<endl;
return 0;
} |
|