アットウィキロゴ

pl0710

class pro{
public static void main(String args[]){
int s,n1,n2,nx1,nx2,nxs1,nxs2;
double th[]=new double[101];
double q[]=new double[101];
double t[]=new double[101];
int op1[]=new int[101];
int op2[]=new int[101];
double rev[][][]=new double[101][3][3];
double u[][][]=new double[101][3][3];
double w[][][]=new double[101][3][3];
double v[][][]=new double[101][3][3];
int goto1[][][]=new int[101][3][3];
int goto2[][][]=new int[101][3][3];
double beta,cost;
double r,sumr,maxr,maxc,maxp;
double v1,w1,maxv;
double p,x,c,u1,r1;
double h;
int j,e;
int t1;
for (s=1;s<101;s++){
th[s]=s;
}


maxr=0;
maxc=0;
maxp=0;
beta=1;
cost=10;
for (n1=1;n1<101;n1++){
for (n2=1;n2<701;n2++){
p=n1;
c=n2;
sumr=0;
for (s=1;s<101;s++){
x=(th[s]-p)/(2*beta);
if (x<0)x=0;
u1=th[s]*x-beta*x*x-p*x-c;
if (u1<0)x=0;
r=p*x+c-cost*x;
if (x==0)r=0;
sumr=sumr+r;
}
if (sumr>maxr)maxp=p;
if (sumr>maxr)maxc=c;
if (sumr>maxr)maxr=sumr;
}
}

System.out.println(maxr);
System.out.println(maxp);
System.out.println(maxc);
p=maxp;
c=maxc;

for (s=1;s<101;s++){
x=(th[s]-p)/(2*beta);
if (x<0)x=0;
u1=th[s]*x-beta*x*x-p*x-c;
if (u1<0)x=0;
r=p*x+c;
if (x==0)r=0;
t[s]=r;
q[s]=x;
}

h=0.1;
t1=0;
while(t1<1000){

for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
r=t[s]+n1*h;
x=q[s]+n2*h;
rev[s][n1+1][n2+1]=r-cost*x;
}
}
}

for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
r=t[s]+n1*h;
x=q[s]+n2*h;
u1=th[s]*x-beta*x*x-r;
u[s][n1+1][n2+1]=u1;
}
}
}

for (s=1;s<100;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
r=t[s]+n1*h;
x=q[s]+n2*h;
u1=th[s+1]*x-beta*x*x-r;
w[s][n1+1][n2+1]=u1;
}
}
}

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=2;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];
if (u1<0)r1=-999;
maxv=0;
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;
}
}
}

nx1=0;
nx2=0;
maxv=-999;
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);

op1[100]=nx1;
op2[100]=nx2;


for (j=1;j<100;j++){
s=100-j;
n1=op1[s+1];
n2=op2[s+1];
op1[s]=goto1[s][n1+1][n2+1];
op2[s]=goto2[s][n1+1][n2+1];
}


for (s=1;s<101;s++){
t[s]=t[s]+op1[s]*h;
q[s]=q[s]+op2[s]*h;
}

e=0;
for (s=1;s<101;s++){
e=e+op1[s]*op1[s];
e=e+op2[s]*op2[s];
}
if (e<2)h=h/2;
if (h<0.001)t1=10000;
System.out.println(e);
t1=t1+1;
}





}
}
最終更新:2010年07月15日 13:05