アットウィキロゴ

071504

class pro{
public static void main(String args[]){
int s,j,e;
int px;
int n1,n2,nx1,nx2,nxs1,nxs2;
double maxv,v1,w1;
double x1,u1,r1,p1;
double beta,cost;
double p,c;
double sumr,maxr,maxp,maxc;
double th[]=new double[101];
double pr[]=new double[101];
double x[]=new double[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];
int op1[]=new int[101];
int op2[]=new int[101];
double h;
int t1,t2;
for (s=1;s<101;s++){
th[s]=s;
}
beta=1;
cost=3;
maxr=0;
maxp=0;
maxc=0;
for (n1=1;n1<101;n1++){
for (n2=1;n2<601;n2++){
p=n1;
c=n2;

sumr=0;
for (s=1;s<101;s++){
x1=(th[s]-p)/(2*beta);
if (x1<0)x1=0;
u1=th[s]*x1-beta*x1*x1-p*x1-c;
if (u1<0)x1=0;
r1=p*x1+c-cost*x1;
if (x1==0)r1=0;
sumr=sumr+r1;
}
if (sumr>maxr)maxp=p;
if (sumr>maxr)maxc=c;
if (sumr>maxr)maxr=sumr;
}
}
System.out.println(maxp);
System.out.println(maxc);
System.out.println(maxr);
p=maxp;
c=maxc;
for (s=1;s<101;s++){
x1=(th[s]-p)/(2*beta);
if (x1<0)x1=0;
u1=th[s]*x1-beta*x1*x1-p*x1-c;
if (u1<0)x1=0;
r1=p*x1+c;
if (x1==0)r1=0;
pr[s]=r1;
x[s]=x1;
System.out.println(pr[s]);
System.out.println(x[s]);
}


h=0.1;
t2=0;
while(t2<5){
h=h/2;
t1=0;
while(t1<1000){
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
p1=pr[s]+n1*h;
x1=x[s]+n2*h;
r1=p1-cost*x1;
if (x1<0)r1=-999;
if (p1<0)r1=-999;
rev[s][n1+1][n2+1]=r1;
}
}
}


for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
p1=pr[s]+n1*h;
x1=x[s]+n2*h;
u1=th[s]*x1-beta*x1*x1-p1;
if (x1<0)u1=-999;
if (u1<0)u1=-999;
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++){
p1=pr[s]+n1*h;
x1=x[s]+n2*h;
u1=th[s+1]*x1-beta*x1*x1-p1;
w[s][n1+1][n2+1]=u1;
}
}
}


for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
u1=u[1][n1+1][n2+1];
r1=rev[1][n1+1][n2+1];
if (u1<0)r1=-999;
v[1][n1+1][n2+1]=r1;
}
}

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];
p1=pr[s]+n1*h;
x1=x[s]+n2*h;
px=0;
if (u1<0)px=100;
if (p1<0)px=100;
if (x1<0)px=100;
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;
}
}
if (px>50)maxv=-999;
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+1][n1+1][n2+1];
op2[s]=goto2[s+1][n1+1][n2+1];
}


for (s=1;s<101;s++){
pr[s]=pr[s]+op1[s]*h;
x[s]=x[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<1)t1=1000;
t1=t1+1;
System.out.println(e);

}
t2=t2+1;
}
for (s=1;s<101;s++){
System.out.println(pr[s]);
System.out.println(x[s]);
}

}
}
最終更新:2010年07月15日 16:18