public class tax42{
public static void main(String[] args) {
int s1,s2,n1,n2;
double tk,tl,tr;
double w1,maxw,maxtk,maxtl;
double[] th1=new double[11];
double[] th2=new double[11];
double[] y1=new double[11];
double[] y2=new double[5];
for (s1=1;s1<11;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<11;s2++){
th2[s2]=0.1*s2;
}
for (n1=0;n1<11;n1++){
y1[n1]=0.1*n1;
}
for (n2=0;n2<5;n2++){
y2[n2]=0.1*n2;
}
maxw=-999;
maxtk=0;
maxtl=0;
for (n1=10;n1<45;n1++){
for (n2=10;n2<45;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr=trs(tk,tl,y1,y2,th1,th2);
w1=wel(tk,tl,tr,y1,y2,th1,th2);
if (w1>maxw)maxtk=tk;
if (w1>maxw)maxtl=tl;
if (w1>maxw)maxw=w1;
}
}
System.out.println(maxtk);
System.out.println(maxtl);
}
public static double wel(double tk,double tl,double tr,double[] y1,double[] y2,double[] th1,double[] th2){
int s1,s2,n1,n2;
double w1;
double[][] c=new double[11][5];
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c[n1][n2]=(1-tk)*y1[n1]+(1-tl)*y2[n2]+tr;
}
}
w1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
n1=mprefer(s1,s2,c,y1,y2,th1,th2);
n2=fprefer(s1,s2,c,y1,y2,th1,th2);
w1=w1+u(c[n1][n2],y1[n1]/th1[s1],y2[n2]/th2[s2]);
}
}
return w1;
}
public static double trs(double tk,double tl,double[] y1,double[] y2,double[] th1,double[] th2){
double b1,b2,tr1,tr2,tr3;
int t;
tr1=0.01;
tr2=0.3;
b1=bud(tk,tl,tr1,y1,y2,th1,th2);
t=0;
while(t<100){
b2=bud(tk,tl,tr2,y1,y2,th1,th2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
if (b2*b2<0.001)t=1000;
t=t+1;
}
return tr2;
}
public static double bud(double tk,double tl,double tr,double[] y1,double[] y2,double[] th1,double[] th2){
int s1,s2,n1,n2;
double b1;
double[][] c=new double[11][5];
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c[n1][n2]=(1-tk)*y1[n1]+(1-tl)*y2[n2]+tr;
}
}
b1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
n1=mprefer(s1,s2,c,y1,y2,th1,th2);
n2=fprefer(s1,s2,c,y1,y2,th1,th2);
b1=b1+y1[n1]+y2[n2]-c[n1][n2];
}
}
return b1;
}
public static int mprefer(int s1,int s2,double[][] c,double[] y1,double[] y2,double[] th1,double[] th2){
double c1,l1,l2,maxu,u1;
int n1,n2,nx;
maxu=-999;
nx=0;
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c1=c[n1][n2];
l1=y1[n1]/th1[s1];
l2=y2[n2]/th2[s2];
u1=u(c1,l1,l2);
if (u1>maxu)nx=n1;
if (u1>maxu)maxu=u1;
}
}
return nx;
}
public static int fprefer(int s1,int s2,double[][] c,double[] y1,double[] y2,double[] th1,double[] th2){
double c1,l1,l2,maxu,u1;
int n1,n2,nx;
maxu=-999;
nx=0;
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c1=c[n1][n2];
l1=y1[n1]/th1[s1];
l2=y2[n2]/th2[s2];
u1=u(c1,l1,l2);
if (u1>maxu)nx=n2;
if (u1>maxu)maxu=u1;
}
}
return nx;
}
public static double u(double c1,double l1,double l2){
double u1,cx1,lx1,lx2;
int h;
cx1=c1;
lx1=l1;
lx2=l2;
h=0;
if (cx1<0)h=100;
if (cx1==0)h=100;
if (lx1<0)h=100;
if (lx1==1)h=100;
if (lx1>1)h=100;
if (lx2<0)h=100;
if (lx2==1)h=100;
if (lx2>1)h=100;
if (h>50)cx1=0.5;
if (h>50)lx1=0.5;
if (h>50)lx2=0.5;
u1=Math.log(cx1)+Math.log(1-lx1)+Math.log(1-lx2);
if (h>50)u1=-999;
return u1;
}
}
最終更新:2010年05月18日 15:57