アットウィキロゴ

071503

class pro{
public static void main(String args[]){
int s,n1,n2,nx1,nx2;
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[101][3][3];
double v[][][]=new double[101][3][3];
double beta,cost;
double r,sumr,maxr,maxc,maxp;
double v1,w1,maxv;
double p,x,c,u1,r1;
double h;
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.01;
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];
maxv=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)maxv=v1;
}
}
v[s][n1+1][n2+1]=maxv;
}
}
}


for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
System.out.println(v[100][n1+1][n2+1]);
}
}






}
}
最終更新:2010年07月15日 11:03