アットウィキロゴ

speed3

package w;
 
class nonlinear{ 
 
 
int[] th= new int[101]; 
int[] c= new int[101]; 
int[] y= new int[101]; 
 
int[] opw= new int[101]; 
int[] opb= new int[101]; 
int[][][] opc= new int[101][21][21]; 
int[][][] opy= new int[101][21][21]; 
 
double h;
double z;
 
 
double[][][] ux= new double[101][21][21]; 
double[][][] wx= new double[101][21][21]; 
double[][][] v= new double[101][21][201];
int[][][] gotow= new int[101][21][201];
int[][][] gotob= new int[101][21][201];
 
 
 
int[][][] nearu= new int[101][21][21]; 
int[][][] nearw= new int[101][21][21]; 
double[][][] chu= new double[101][21][21]; 
int[] ws= new int[101]; 
 
int s,n1,n2,m1,m2,mx;
double c1,l1,u1;
 
double maxu;
 
void makedata(){ 
 
 
for (s=1;s<101;s++){ 
for (n1=-10;n1<11;n1++){ 
for (n2=-10;n2<11;n2++){ 
c1=(c[s]+n1)*h; 
l1=(double)(y[s]+n2)/th[s]; 
u1=u(c1,1-l1);   
ux[s][n1+10][n2+10]=u1; 
} 
} 
} 
 
 
 
for (s=1;s<100;s++){ 
for (n1=-10;n1<11;n1++){ 
for (n2=-10;n2<11;n2++){ 
c1=(c[s]+n1)*h; 
l1=(double)(y[s]+n2)/th[s+1]; 
u1=u(c1,1-l1);   
wx[s][n1+10][n2+10]=u1; 
} 
} 
} 
 
 
 
for (s=1;s<101;s++){ 
for (n1=-10;n1<11;n1++){ 
for (n2=-10;n2<11;n2++){
nearu[s][n1+10][n2+10]=search(ux[s][n1+10][n2+10]); 
} 
} 
} 
 
 
for (s=1;s<100;s++){ 
for (n1=-10;n1<11;n1++){ 
for (n2=-10;n2<11;n2++){
nearw[s][n1+10][n2+10]=search(wx[s][n1+10][n2+10]); 
} 
} 
} 
 
for (s=1;s<100;s++){ 
ws[s]=nearw[s][10][10];
}
 
int x1,x2;
 
for (s=1;s<100;s++){ 
for (m1=-10;m1<11;m1++){ 
for (m2=-10;m2<11;m2++){
maxu=-999;
x1=0;
x2=0;
for (n2=-10;n2<11;n2++){
n1=n2-m2;
z=0;
if(n1>5)z=100;
if(n1<-5)z=100;
if(z>50)n1=0;
u1=ux[s][n1+10][n2+10];
mx=nearw[s][n1+10][n2+10];
if(mx>m1+ws[s])z=100;
if(z>50)u1=-999;
if(u1>maxu)x1=n1;
if(u1>maxu)x2=n2;
if(u1>maxu)maxu=u1;
}
chu[s][m1+10][m2+10]=maxu;
opc[s][m1+10][m2+10]=x1+c[s];
opy[s][m1+10][m2+10]=x2+y[s];
}
}
}
 
for (m1=-10;m1<11;m1++){ 
for (m2=-100;m2<101;m2++){
v[1][m1+10][m2+100]=-999;
}
}
 
 
 
for (m1=-10;m1<11;m1++){ 
for (m2=-10;m2<10;m2++){
v[1][m1+10][m2+100]=chu[1][m1+10][m2+10];
}
}
 
int bx,bxs,p1,bps,ps;
double v1,maxv;
int yy,yys;
 
for (s=2;s<100;s++){ 
for (m1=-10;m1<11;m1++){ 
for (m2=-100;m2<101;m2++){
maxv=-999;
ps=0;
bps=0;
for(bx=-10;bx<11;bx++){
u1=chu[s][m1+10][bx+10];
 
 
p1=search(u1)-ws[s-1];
bxs=m2-bx;
z=0;
if(bxs>100)z=100;
if(bxs<-100)z=100;
if(p1>10)z=100;
if(p1<-10)z=100;
if(z>50)bxs=0;
if(z>50)p1=0;
v1=u1+v[s-1][p1+10][bxs+100];
if(z>50)v1=-999;
if(v1>maxv)bps=bxs;
if(v1>maxv)ps=p1;
if(v1>maxv)maxv=v1;
}
v[s][m1+10][m2+100]=maxv;
gotob[s][m1+10][m2+100]=bps;
gotow[s][m1+10][m2+100]=ps;
}
}
}
 
 
int nx1,nx2,px;
 
s=100;
maxv=-999;
nx1=0;
nx2=0;
bxs=0;
px=0;
for (n1=-10;n1<11;n1++){ 
for (n2=-10;n2<11;n2++){
u1=ux[s][n1+10][n2+10];
p1=nearu[s][n1+10][n2+10]-ws[s-1];
 
bx=n1-n2;
z=0;
if(p1<-10)z=100;
if(p1>10)z=100;
if(z>50)p1=0;
 
v1=u1+v[s-1][p1+10][bx+100];
 
if(z>50)v1=-999;
if(v1>maxv)nx1=n1;
if(v1>maxv)nx2=n2;
if(v1>maxv)px=p1;
if(v1>maxv)bxs=bx;
 
if(v1>maxv)maxv=v1;
 
 
} 
} 
 
 
opb[99]=bxs;
opw[99]=px;
 
int j;
for(j=1;j<99;j++){
s=100-j;
bx=opb[s];
px=opw[s];
opb[s-1]=gotob[s][px+10][bx+100];
opw[s-1]=gotow[s][px+10][bx+100];
}
 
s=1;
bx=opb[s];
px=opw[s];
c[s]=opc[s][px+10][bx+10];
y[s]=opy[s][px+10][bx+10];
 
for(s=2;s<100;s++){
bx=opb[s]-opb[s-1];
px=opw[s];
c[s]=opc[s][px+10][bx+10];
y[s]=opy[s][px+10][bx+10];
}
 
c[100]=c[100]+nx1;
 
y[100]=y[100]+nx2;
 
System.out.println(maxv);
 
 
 
} 
 
 
 
int search(double u1){ 
double c1;
int n1;
n1=-999;
c1=0;
if(u1>-900)c1=Math.exp(u1);
if(u1>-900)n1=(int)(c1/h);
return n1; 
} 
 
 
double u(double c1,double x1){ 
double u1,c2,x2; 
int pp; 
pp=0; 
c2=c1; 
x2=x1; 
if (c2<0)pp=100; 
if (x2<0)pp=100; 
if (x2>1)pp=100; 
if (x2==0)pp=100; 
if (pp>50)c2=0.5; 
if (pp>50)x2=0.5; 
u1=Math.log(c2)+Math.log(x2); 
if (pp>50)u1=-999; 
return u1; 
} 
 
}
 
最終更新:2013年10月02日 13:05