アットウィキロゴ

2*20

class pro{
public static void main(String args[]){
int m,mx,s1,s2,n,n1,n2,n3,n4,n5,n6;
int p1,p2;
int nx1,nx2,nx3,nx4,nx5,nx6;
int nxs1,nxs2,nxs3,nxs4,nxs5,nxs6;
int px,px1,px2,pxs1,pxs2;
double tk,tl,tr,ww,maxw,tks,tls,trs;
double th1[]=new double[21];
double th2[]=new double[3];
double c[][]=new double[21][3];
double y1[][]=new double[21][3];
double y2[][]=new double[21][3];
double u[][][]=new double[21][3][28];
double w[][][]=new double[21][3][28];
double dc,dy;
int b[]=new int[28];
double z[][]=new double[21][28];
double v[][][][]=new double[21][28][28][11];
int goto1[][][][]=new int[21][28][28][11];
int goto2[][][][]=new int[21][28][28][11];
int gotom[][][][]=new int[21][28][28][11];
double endv[][]=new double[28][28];
int end1[][]=new int[28][28];
int end2[][]=new int[28][28];
int endm[][]=new int[28][28];
int op[][]=new int[101][3];
int t1,t2,t7;
int x[][]=new int[28][4];
double h,ux1,ux2;
double cp,yp1,yp2,cs,ys1,ys2;
double w1,w2,z1,u1,u2,v1,v2,v3,maxv,supv;
int max1,max2,max3,max4,max5,max6;
int mxs;
int sup1,sup2,d1,d2;
int j,e;
for (s1=1;s1<21;s1++){
th1[s1]=0.1*s1;
}

for (s2=1;s2<3;s2++){
th2[s2]=0.5*s2;
}

n=0;
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
n=n+1;
x[n][1]=n1;
x[n][2]=n2;
x[n][3]=n3;
}
}
}


maxw=-999;
tks=0;
tls=0;
trs=0;
for (n1=5;n1<40;n1++){
for (n2=5;n2<40;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr=trs(tk,tl,th1,th2);
ww=wel(tk,tl,tr,th1,th2);
if (ww>maxw)tks=tk;
if (ww>maxw)tls=tl;
if (ww>maxw)trs=tr;
if (ww>maxw)maxw=ww;
}
}
System.out.println(tks);
System.out.println(tls);

tk=tks;
tl=tls;
tr=trs;

for (s1=1;s1<21;s1++){
for (s2=1;s2<3;s2++){
y1[s1][s2]=th1[s1]*mlx(s1,s2,tk,tl,tr,th1,th2);
y2[s1][s2]=th2[s2]*flx(s1,s2,tk,tl,tr,th1,th2);
c[s1][s2]=(1-tk)*y1[s1][s2]+(1-tl)*y2[s1][s2]+tr;
}
}
h=0.01;
t2=0;
while(t2<5){
h=h/2;
t1=0;
while(t1<10){

for (s1=1;s1<21;s1++){
for (s2=1;s2<3;s2++){
for (n=1;n<28;n++){
n1=x[n][1];
n2=x[n][2];
n3=x[n][3];
cs=c[s1][s2]+n3*h;
ys1=y1[s1][s2]+n1*h;
ys2=y2[s1][s2]+n2*h;
u[s1][s2][n]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2]);    
}
}
}

for (s1=1;s1<20;s1++){
for (s2=1;s2<3;s2++){
for (n=1;n<28;n++){  
n1=x[n][1];
n2=x[n][2];
n3=x[n][3];
cs=c[s1][s2]+n3*h;
ys1=y1[s1][s2]+n1*h;
ys2=y2[s1][s2]+n2*h;
w[s1][s2][n]=ux(cs,1-ys1/th1[s1+1],1-ys2/th2[s2]);    
}
}
}

for (n=1;n<28;n++){  
n1=x[n][1];
n2=x[n][2];
n3=x[n][3];
b[n]=n1+n2-n3;    
}  

for (s1=1;s1<21;s1++){  
for (n=1;n<28;n++){
n1=x[n][1];
n2=x[n][2];
n3=x[n][3];  
cs=c[s1][1]+n3*h;
ys1=y1[s1][1]+n1*h;
ys2=y2[s1][1]+n2*h;
z[s1][n]=ux(cs,1-ys1/th1[s1],1-ys2/th2[2]);  
}
}  



for (p1=1;p1<28;p1++){
for (p2=1;p2<28;p2++){
for (m=-5;m<6;m++){
v[1][p1][p2][m+5]=-999;    
}
}
}

for (p1=1;p1<28;p1++){
for (p2=1;p2<28;p2++){
m=b[p1]+b[p2];
u1=u[1][1][p1];
u2=u[1][2][p2];
z1=z[1][p1];
px=0;
if (z1>u2)px=100;
if (m>5)px=100;
if (m<-5)px=100;
if (px>50)m=0;
if (px>50)u1=-999;
if (px>50)u2=0;
v[1][p1][p2][m+5]=u1+u2;
}
}    


for (s1=2;s1<20;s1++){
for (p1=1;p1<28;p1++){
for (p2=1;p2<28;p2++){
for (m=-5;m<6;m++){
u1=u[s1][1][p1];
u2=u[s1][2][p2];
z1=z[s1][p1];
mx=m-b[p1]-b[p2];
px=0;
if (mx>5)px=100;
if (mx<-5)px=100;
if (z1>u2)px=100;
if (px>50)mx=0;
maxv=-999;
pxs1=0;
pxs2=0;  
for (px1=1;px1<28;px1++){
for (px2=1;px2<28;px2++){
v1=u1+u2+v[s1-1][px1][px2][mx+5];
if(w[s1-1][2][px2]>u2)v1=-999;
if(w[s1-1][1][px1]>u1)v1=-999;
if (v1>maxv)pxs1=px1;
if (v1>maxv)pxs2=px2;
if (v1>maxv)maxv=v1;
}
}  
if (px>50)maxv=-999;
goto1[s1][p1][p2][m+5]=pxs1;
goto2[s1][p1][p2][m+5]=pxs2;
gotom[s1][p1][p2][m+5]=mx;
v[s1][p1][p2][m+5]=maxv;
}
}
}
}  





for (p1=1;p1<28;p1++){
for (p2=1;p2<28;p2++){
u1=u[20][1][p1];
u2=u[20][2][p2];
z1=z[20][p1];
mx=-b[p1]-b[p2];
px=0;
if (mx>5)px=100;
if (mx<-5)px=100;
if (z1>u2)px=100;
if (px>50)mx=0;
pxs1=0;
pxs2=0;  
maxv=-999;
for (px1=1;px1<28;px1++){
for (px2=1;px2<28;px2++){
v1=u1+u2+v[19][px1][px2][mx+5];
if(w[19][2][px2]>u2)v1=-999;
if(w[19][1][px1]>u1)v1=-999;
if (v1>maxv)pxs1=px1;
if (v1>maxv)pxs2=px2;
if (v1>maxv)maxv=v1;
}
}  
if (px>50)maxv=-999;
end1[p1][p2]=pxs1;
end2[p1][p2]=pxs2;
endm[p1][p2]=mx;
endv[p1][p2]=maxv;
}
}  

px1=0;
px2=0;
maxv=-999;
for (p1=1;p1<28;p1++){
for (p2=1;p2<28;p2++){
if (endv[p1][p2]>maxv)px1=p1;
if (endv[p1][p2]>maxv)px2=p2;
if (endv[p1][p2]>maxv)maxv=endv[p1][p2];
}
}  
  

op[20][1]=px1;
op[20][2]=px2;  

p1=op[20][1];
p2=op[20][2];  

op[19][1]=end1[p1][p2];
op[19][2]=end2[p1][p2];

System.out.println(t1);
System.out.println(maxv);
m=endm[p1][p2];
for (j=1;j<19;j++){
s1=19-j;
p1=op[s1+1][1];
p2=op[s1+1][2];
op[s1][1]=goto1[s1+1][p1][p2][m+5];
op[s1][2]=goto2[s1+1][p1][p2][m+5];
m=gotom[s1+1][p1][p2][m+5];
}

e=0;
for (s1=2;s1<21;s1++){
for (s2=1;s2<3;s2++){
n=op[s1][s2];
n1=x[n][1];
n2=x[n][2];
n3=x[n][3];
e=e+n1*n1;
e=e+n2*n2;
e=e+n3*n3;
}
}

System.out.println(e);

for (s1=2;s1<21;s1++){
for (s2=1;s2<3;s2++){
n=op[s1][s2];
n1=x[n][1];
n2=x[n][2];
n3=x[n][3];
c[s1][s2]=c[s1][s2]+h*n3;
y1[s1][s2]=y1[s1][s2]+h*n1;
y2[s1][s2]=y2[s1][s2]+h*n2;
}
}
if (e<2)t1=1000;
t1=t1+1;
}
t2=t2+1;
}

for (s1=1;s1<21;s1++){
System.out.println(s1);
for (s2=1;s2<3;s2++){
System.out.println(c[s1][s2]);
System.out.println(y1[s1][s2]);
System.out.println(y2[s1][s2]);
}
}

for (s1=1;s1<20;s1++){
dc=c[s1+1][1]-c[s1][1];
dy=y1[s1+1][1]-y1[s1][1];
System.out.println(1-dc/dy);
}

}
static double trs(double tk,double tl,double[] th1,double[] th2){
double tr1,tr2,tr3,b1,b2;
int t1;
tr1=0.01;
tr2=0.4;
tr3=0;
b1=bud(tk,tl,tr1,th1,th2);
t1=0;
while(t1<100){
b2=bud(tk,tl,tr2,th1,th2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.001)t1=1000;
t1=t1+1;
}
return tr3;
}

static double wel(double tk,double tl,double tr,double[] th1,double[] th2){
int s1,s2;
double ww,w1,w2,l1,l2,c1;
ww=0;
for (s1=1;s1<21;s1++){
for (s2=1;s2<3;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
ww=ww+Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
}
}
return ww;
}

static double bud(double tk,double tl,double tr,double[] th1,double[] th2){
int s1,s2;
double b1,w1,w2,l1,l2,c1;
b1=0;
for (s1=1;s1<21;s1++){
for (s2=1;s2<3;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
b1=b1+th1[s1]*l1+th2[s2]*l2-c1;
}
}
return b1;
}

static double mlx(int s1,int s2,double tk,double tl,double tr,double[] th1,double[] th2){
double uc,u1,u2,w1,w2,l1,l2,u3,u4,maxu;
double lx1,lx2,lx3,lx4,c1;
int px;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
if (l1<0)l1=0;
if (l2<0)l2=0;
c1=w1*l1+w2*l2+tr;
lx1=l1;
u1=Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
l1=(w1-tr)/(2*w1);
if (l1<0)l1=0;
lx2=l1;
c1=w1*l1+tr;
u2=Math.log(c1)+Math.log(1-l1)+Math.log(1);
l2=(w2-tr)/(2*w2);
if (l2<0)l2=0;
lx3=0;
c1=w2*l2+tr;
u3=Math.log(c1)+Math.log(1-l2)+Math.log(1);
u4=Math.log(tr)+Math.log(1)+Math.log(1);
lx4=0;
maxu=-999;
l1=0;
if (u1>maxu)l1=lx1;
if (u1>maxu)maxu=u1;
if (u2>maxu)l1=lx2;
if (u2>maxu)maxu=u2;
if (u3>maxu)l1=lx3;
if (u3>maxu) maxu=u3;
if (u4>maxu)l1=lx4;
if (u4>maxu)maxu=u4;
return l1;
}
static double flx(int s1,int s2,double tk,double tl,double tr,double[] th1,double[] th2){
double uc,u1,u2,w1,w2,l1,l2,u3,u4,maxu;
double lx1,lx2,lx3,lx4,c1;
int px;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
if (l1<0)l1=0;
if (l2<0)l2=0;
c1=w1*l1+w2*l2+tr;
lx1=l2;
u1=Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
l1=(w1-tr)/(2*w1);
if (l1<0)l1=0;
lx2=0;
c1=w1*l1+tr;
u2=Math.log(c1)+Math.log(1-l1)+Math.log(1);
l2=(w2-tr)/(2*w2);
if (l2<0)l2=0;
lx3=l2;
c1=w2*l2+tr;
u3=Math.log(c1)+Math.log(1-l2)+Math.log(1);
u4=Math.log(tr)+Math.log(1)+Math.log(1);
lx4=0;
maxu=-999;
l2=0;
if (u1>maxu)l2=lx1;
if (u1>maxu)  maxu=u1;
if (u2>maxu)  l2=lx2;
if (u2>maxu)  maxu=u2;
if (u3>maxu)  l2=lx3;
if (u3>maxu)  maxu=u3;
if (u4>maxu)  l2=lx4;
if (u4>maxu)  maxu=u4;
return l2;
}
static double ux(double c1,double x1,double x2){
double c2,x3,x4,u1;
int px;
c2=c1;
x3=x1;
x4=x2;
px=0;
if (c2<0)px=100;
if (c2==0)px=100;
if (x3<0)px=100;
if (x3==0)px=100;
if (x3>1)px=100;
if (x4<0)px=100;
if (x4==0)px=100;
if (x4>1)px=100;
if (px>50)c2=0.5;
if (px>50)x3=0.5;
if (px>50)x4=0.5;
u1=Math.log(c2)+Math.log(x3)+Math.log(x4);
if (px>50)u1=-999;
return u1;
}
}
最終更新:2010年07月09日 03:40