class tax11{
public static void main(String args[]){
int s1,s2,n1,n2;
double th1[]=new double[11];
double th2[]=new double[11];
double y1[][]=new double[11][11];
double y2[][]=new double[11][11];
double c[][]=new double[11][11];
double tk,tl,tr,tks,tls;
double b1,w1,maxw;
for (s1=1;s1<11;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<11;s2++){
th2[s2]=0.1*s2;
}
maxw=-999;
tls=0;
tks=0;
for (n1=5;n1<41;n1++){
for (n2=5;n2<41;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr=trs(tk,tl,th1,th2);
w1=wel(tk,tl,tr,th1,th2);
if (w1>maxw)tks=tk;
if (w1>maxw)tls=tl;
if (w1>maxw)maxw=w1;
}
}
tk=tks;
tl=tls;
tr=trs(tk,tl,th1,th2);
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
y1[s1][s2]=th1[s1]*lx1(s1,s2,tk,tl,tr,th1,th2);
y2[s1][s2]=th2[s2]*lx2(s1,s2,tk,tl,tr,th1,th2);
c[s1][s2]=(1-tk)*y1[s1][s2]+(1-tl)*y2[s1][s2]+tr;
}
}
System.out.println(tks);
System.out.println(tls);
}
public static double lx1(int s1,int s2,double tk,double tl,double tr,double th1[],double th2[]){
double c1,w1,w2,l1,l2;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
if (l1<0)l2=(w2-tr)/(2*w2);
if (l1<0)l1=0;
if (l2<0)l1=(w1-tr)/(2*w1);
if (l2<0)l2=0;
return l1;
}
public static double cx(int s1,int s2,double tk,double tl,double tr,double th1[],double th2[]){
double c1,w1,w2,l1,l2;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=lx1(s1,s2,tk,tl,tr,th1,th2);
l2=lx2(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
return c1;
}
public static double lx2(int s1,int s2,double tk,double tl,double tr,double th1[],double th2[]){
double c1,w1,w2,l1,l2;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
if (l1<0)l2=(w2-tr)/(2*w2);
if (l1<0)l1=0;
if (l2<0)l1=(w1-tr)/(2*w1);
if (l2<0)l2=0;
return l2;
}
public static double wel(double tk,double tl,double tr,double th1[],double th2[]){
double c1,l1,l2,w1;
int s1,s2;
w1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
l1=lx1(s1,s2,tk,tl,tr,th1,th2);
l2=lx2(s1,s2,tk,tl,tr,th1,th2);
c1=cx(s1,s2,tk,tl,tr,th1,th2);
w1=w1+Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
}
}
return w1;
}
public static double bud(double tk,double tl,double tr,double th1[],double th2[]){
double c1,y1,y2,b1;
int s1,s2;
b1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
y1=th1[s1]*lx1(s1,s2,tk,tl,tr,th1,th2);
y2=th2[s2]*lx2(s1,s2,tk,tl,tr,th1,th2);
c1=cx(s1,s2,tk,tl,tr,th1,th2);
b1=b1+y1+y2-c1;
}
}
return b1;
}
public static double trs(double tk,double tl,double th1[],double th2[]){
double tr1,tr2,tr3,b1,b2;
int t;
tr1=0.1;
tr2=0.2;
b1=bud(tk,tl,tr1,th1,th2);
t=0;
while (t<100){
b2=bud(tk,tk,tr2,th1,th2);
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;
}
}
最終更新:2010年05月09日 10:02