class pro{
public static void main(String args[]){
int s,n,n1,n2,px,nx1,nx2,nxs1,nxs2;
double th[]=new double[101];
double q[]=new double[101];
double t[]=new double[101];
double rev[][][]=new double[101][3][3];
double u[][][]=new double[101][3][3];
double w[][][]=new double[100][3][3];
double v[][][]=new double[101][3][3];
int goto1[][][]=new int[101][3][3];
int goto2[][][]=new int[101][3][3];
int op[]=new int[101];
int oq[]=new int[101];
double p,q1;
double beta;
double r,maxv,maxp;
double r1,u1,v1,w1;
double h;
double t1;
int j,e,t5;
beta=1;
for (s=1;s<101;s++){
th[s]=s;
}
maxv=-999;
maxp=0;
for (n=1;n<50;n++){
p=n;
r=0;
for (s=1;s<101;s++){
q1=(th[s]-p)/beta;
if (q1<0)q1=0;
r=r+p*q1;
}
if (r>maxv)maxp=p;
if (r>maxv)maxv=r;
}
p=maxp;
for (s=1;s<101;s++){
q1=(th[s]-p)/beta;
if (q1<0)q1=0;
q[s]=q1;
t[s]=p*q1;
}
h=0.01;
t5=0;
while(t5<100){
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
t1=t[s]+n1*h;
q1=q[s]+n2*h;
px=0;
if (q1<0)px=100;
if (t1<0)px=100;
if (px>50)t1=-999;
rev[s][n1+1][n2+1]=t1;
}
}
}
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
t1=t[s]+n1*h;
q1=q[s]+n2*h;
u[s][n1+1][n2+1]=th[s]*q1-beta*q1*q1-t1;
}
}
}
for (s=1;s<100;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
t1=t[s]+n1*h;
q1=q[s]+n2*h;
w[s][n1+1][n2+1]=th[s+1]*q1-beta*q1*q1-t1;
}
}
}
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
v[1][n1+1][n2+1]=rev[1][n1+1][n2+1];
}
}
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
r1=rev[s][n1+1][n2+1];
u1=u[s][n1+1][n2+1];
maxv=-999;
nxs1=0;
nxs2=0;
for (nx1=-1;nx1<2;nx1++){
for (nx2=-1;nx2<2;nx2++){
v1=r1+v[s-1][nx1+1][nx2+1];
w1=w[s-1][nx1+1][nx2+1];
if (w1>u1)v1=-999;
if (v1>maxv)nxs1=nx1;
if (v1>maxv)nxs2=nx2;
if (v1>maxv)maxv=v1;
}
}
goto1[s][n1+1][n2+1]=nxs1;
goto2[s][n1+1][n2+1]=nxs2;
v[s][n1+1][n2+1]=maxv;
}
}
}
maxv=-999;
nx1=0;
nx2=0;
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
if (v[100][n1+1][n2+1]>maxv)nx1=n1;
if (v[100][n1+1][n2+1]>maxv)nx2=n2;
if (v[100][n1+1][n2+1]>maxv)maxv=v[100][n1+1][n2+1];
}
}
System.out.println(maxv);
op[100]=nx1;
oq[100]=nx2;
for (j=1;j<100;j++){
s=100-j;
n1=op[s+1];
n2=oq[s+1];
op[s]=goto1[s][n1+1][n2+1];
oq[s]=goto2[s][n1+1][n2+1];
}
for (s=1;s<101;s++){
t[s]=t[s]+op[s]*h;
q[s]=q[s]+oq[s]*h;
}
e=0;
for (s=1;s<101;s++){
e=e+op[s]*op[s];
e=e+oq[s]*oq[s];
}
if (e<1)t5=1000;
t5=t5+1;
System.out.println(e);
}
}
}
最終更新:2010年07月10日 15:22