アットウィキロゴ

練習3

package th3;
 
 
public class pro {
 
    int[] c=new int[101];
    int[] y=new int[101];
    int[] th=new int[101];
        double[] us=new double[101];
     double[] du=new double[201];
    int s;
    double delta;
     int[] rank=new int[201];
 
 
    public static void main(String[] args) {
       pro test=new pro();
    }
   pro(){ 
 
       delta=0.01;
   for(s=1;s<101;s++){   
   c[s]=5*s;
   y[s]=5*s;
   th[s]=10*s;
   }
 
   int tr;
 
for(tr=1;tr<1000;tr++){   
 
 for(s=1;s<101;s++){
 us[s]=u(c[s],y[s],th[s]);  
 }
 
 for(s=1;s<101;s++){
 du[s]=u(c[s]+1,y[s],th[s])-us[s];
 } 
 
 for(s=1;s<101;s++){
 du[s+100]=-(u(c[s],y[s]+1,th[s])-us[s]);  
 } 
 
 ranking();
 
 shuffle();
 
 for(s=1;s<100;s++){
 bomb(s);
}
 
}   
 
 
   for(s=1;s<101;s++){
   System.out.println(c[s]+","+y[s]);
   }
 
 
 
 
 
 
   }
 
   void bomb(int s){
 
  double w1,u1;
  int bomb;
 
  w1=u(c[s],y[s],th[s+1]);
  u1=u(c[s+1],y[s+1],th[s+1]);
 
  bomb=0;
  if(w1>u1)bomb=100;
 
  if(bomb>50){
  c[s]=c[s]-1;
  y[s]=y[s]+1;
  if(c[s]<0)c[s]=0;
  }
 
   }
 
    void shuffle(){
 
       int b1,s;
       b1=0;
       int k;
 
   for(s=1;s<101;s++){
   b1=b1+(y[s]-c[s]);
   }
 
  if(b1==0)pon();
  if(b1==0)pon2();
  if(b1>0)pon();
  if(b1<0)pon2();
 
 
 
 
 
   }
 
   void pon(){
 
  int s,t,h,p;
 for(p=1;p<30;p++){
 t=1;      
 s=rank[p];
 if(s>100)t=2;
 if(s>100)s=s-100;
 if(t==1)c[s]=c[s]+1;
 if(t==2)y[s]=y[s]-1;
 h=0;
 if(t==2)h=h+1;
 if(y[s]<0)h=h+1;
if(h==2)y[s]=0; 
 
 }
 
   }
 
  void pon2(){
 
  int s,t,h,p;
 for(p=1;p<30;p++){
  t=1;      
 s=rank[201-p];
 if(s>100)t=2;
 if(s>100)s=s-100;
 if(t==1)c[s]=c[s]-1;
 if(t==2)y[s]=y[s]+1;
 h=0;
 if(t==1)h=h+1;
 if(c[s]<0)h=h+1;
if(h==2)c[s]=0; 
 } 
 
 }
 
 
 
   void ranking(){ 
int r,s,sx,h; 
int[] ch=new int[201];
double maxu;
int t;
 
for(r=1;r<201;r++){ 
t=0;
sx=0; 
maxu=-999; 
for(s=1;s<201;s++){ 
h=0; 
if(du[s]>maxu)h=h+1; 
if(ch[s]<50)h=h+1; 
if(h==2)maxu=du[s]; 
if(h==2)sx=s; 
}
rank[r]=sx; 
ch[sx]=100; 
}
 
 
}
 
 
double u(int c1,int y1,int th1){
double u1;
u1=Math.log(c1*delta)+Math.log(1-(double)y1/th1); 
return u1;
}
 
 
 
}
 
最終更新:2014年03月24日 09:36