#include
#include<math.h>
const int N = 10000;
int N2;
float all = 0.0; //所有的number的總發生次數
int index = 0; //計算不重覆的number有几個
int index_b = 0;//系數
int allofsource = 0;
bool isfind;
float v = 0.1;//想求的值
struct p
{
float number;
float counter;
float binding;
float pro;
};
//存方程式系數
struct l
{
float pro;
float sij;
};
float binary(float w , l *b)
{
static float l = 0;
static float r = 1;
double temp = 0; for(int i = 0;i < N2;i )
temp = temp b[i].pro * pow(2.71 , w * b[i].sij); cout<= 0.9999 && temp <= 1 )
return w; if(temp < 1)
{
l = w;
w = l (r - l) / 2.0;
}
else if(temp > 1)
{
r = w;
w = l (r - l) / 2.0;
} binary(w , b);
}
void main()
{ p *a = new p[N];
for(int i = 0;i < N;i )
{
a[i].number = 1;
a[i].counter = 0;
}
int number,binding;
FILE *infile = fopen("d:\\a.txt","rt"); //計算所有number發生的數目
while(fscanf(infile,"%d%d",&number,&binding) != EOF)
{ isfind = false;
for( int i = 0;i < N;i )
{
if(a[i].number == number)
{
a[i].counter ;
isfind = true;
break;
}
}
if(!isfind)
{
a[index].number = number;
a[index].counter ;
a[index].binding = binding;
index ;
}
}
fclose(infile); for(int i = 0; i < index; i )
all = all a[i].counter; for(int i = 0; i < index; i )
a[i].pro = a[i].counter / all ; N2 = index * index ; l *b = new l[N2];//存系數 for(int i = 0; i < index ; i )
for(int j = 0; j < index ; j )
{
b[index_b].pro = a[i].pro * a[j].pro;
if(a[i].number == a[j].number)
b[index_b].sij = 10;
else if(a[i].binding == a[j].binding)
b[index_b].sij = 2;
else
b[index_b].sij = -9;
index_b ;
}
delete []a;
v = binary(v,b);
delete []b;
cout<>index;
}
=============================================================
上面是c 程式碼,用builder 跑時會發生錯誤,但我找了很久,不知錯在哪
不知有哪位大大可以幫忙解決,謝謝囉 ^^