#include <stdio.h>
#include <math.h>
double bud(double tk,double tl,double tr){
int s1,s2,j;
double bx,w1,w2,c1,l1,l2;
double th1[11],th2[11];
for (s1=1;s1<=10;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<=10;s2++){
th2[s2]=0.1*s2;
}
bx=0;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
j=0;
if (l1<0) j=j+1;
if (l2<0) j=j+1;
if (j==2) l1=0;
if (j==2) l2=0;
if (j==2) c1=tr;
j=0;
if (l1<0) j=j+1;
if (l2>0) j=j+1;
if (j==2) l1=0;
if (j==2) l2=(w2-tr)/(2*w2);
if (j==2) c1=w2*l2+tr;
j=0;
if (l1>0) j=j+1;
if (l2<0) j=j+1;
if (j==2) l2=0;
if (j==2) l1=(w1-tr)/(2*w1);
if (j==2) c1=w1*l1+tr;
bx=bx+th1[s1]*l1+th2[s2]*l2-c1;
}
}
return bx;
}
double trs(double tk,double tl){
double trtr,tr1,tr2,tr3,b1,b2;
int t;
tr1=0.05;
tr2=0.1;
b1=bud(tk,tl,tr1);
t=0;
while (t<100){
b2=bud(tk,tl,tr2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
if (b2*b2<0.0001)t=1000;
t=t+1;
}
return tr2;
}
double wel(double tk,double tl,double tr){
int s1,s2,j;
double we,w1,w2,c1,l1,l2;
double th1[11],th2[11];
for (s1=1;s1<=10;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<=10;s2++){
th2[s2]=0.1*s2;
}
we=0;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
j=0;
if (l1<0) j=j+1;
if (l2<0) j=j+1;
if (j==2) l1=0;
if (j==2) l2=0;
if (j==2) c1=tr;
j=0;
if (l1<0) j=j+1;
if (l2>0) j=j+1;
if (j==2) l1=0;
if (j==2) l2=(w2-tr)/(2*w2);
if (j==2) c1=w2*l2+tr;
j=0;
if (l1>0) j=j+1;
if (l2<0) j=j+1;
if (j==2) l2=0;
if (j==2) l1=(w1-tr)/(2*w1);
if (j==2) c1=w1*l1+tr;
we=we+log(c1)+log(1-l1)+log(1-l2);
}
}
return we;
}
int main(void){
double th1[11],th2[11];
int s1,s2,j,t,m1,m2;
double tk,tl,tr,we;
double maxw,maxk,maxl,maxtr;
double c[11][11],y1[11][11],y2[11][11];
double c1,l1,l2,w1,w2;
for (s1=1;s1<=10;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<=10;s2++){
th2[s2]=0.1*s2;
}
maxw=-999;
for (m1=10;m1<=40;m1++){
for (m2=10;m2<=40;m2++){
tk=0.01*m1;
tl=0.01*m2;
tr=trs(tk,tl);
we=wel(tk,tl,tr);
if (we>maxw) maxtr=tr;
if (we>maxw) maxk=tk;
if (we>maxw) maxl=tl;
if (we>maxw) maxw=we;
}
}
tk=maxk;
tl=maxl;
tr=maxtr;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
j=0;
if (l1<0) j=j+1;
if (l2<0) j=j+1;
if (j==2) l1=0;
if (j==2) l2=0;
if (j==2) c1=tr;
j=0;
if (l1<0) j=j+1;
if (l2>0) j=j+1;
if (j==2) l1=0;
if (j==2) l2=(w2-tr)/(2*w2);
if (j==2) c1=w2*l2+tr;
j=0;
if (l1>0) j=j+1;
if (l2<0) j=j+1;
if (j==2) l2=0;
if (j==2) l1=(w1-tr)/(2*w1);
if (j==2) c1=w1*l1+tr;
c[s1][s2]=c1;
y1[s1][s2]=th1[s1]*l1;
y2[s1][s2]=th2[s2]*l2;
}
}
return 0;
}
最終更新:2009年11月29日 10:17