アットウィキロゴ

spin

package ptax;
 
 
public class pro {
 
 
    int[] c=new int[101];
    int[] y=new int[101];
    int[] dc=new int[101];
    int[] dy=new int[101];
    int s,th;
    int avg_c,avg_y,bud;
 
 
    public static void main(String[] args) {
        pro test=new pro();
    }
 
    pro(){
 
    th=100;
    for(s=1;s<101;s++){
    c[s]=10;
    y[s]=60;
    dc[s]=0;
    dy[s]=0;
    }
 
    avg();
 
 
    int tr;
 
    for(tr=1;tr<1000;tr++){
 
        bud=bud();
 
        move(); 
   for(s=1;s<101;s++){
  trial(s);
   }
 
 
    }
 
       System.out.println(bud);   
    }
 
    void trial(int s){
 
        int m1,m2;
 
   m1=avgmet(s); 
 
   m2=minmet(s);
 
  if(m1>20)spin(s);
 
  if(m2<2)spin(s);
 
   double p1=Math.random();
 
 
   }
 
    void spin(int s){
 
        double p1;
 
        p1=Math.random();
 
if(bud>0){
if(p1<0.7)spin_a(s);
if(p1>0.7)spin_b(s);
}   
 
 if(bud<0){
if(p1<0.7)spin_b(s);
if(p1>0.7)spin_a(s);
}    
 
}
 
 
 
 
 
 
    void spin_a(int s){
    double uc,uy;
 
    uc=u(c[s]+1,y[s],th)-u(c[s],y[s],th);
    uy=u(c[s],y[s]-1,th)-u(c[s],y[s],th); 
 
      dc[s]=0;
      dy[s]=0;
 
      dc[s]=0;
      dy[s]=0;
 
 
        double p1;
 
        p1=Math.random();
 
      if(uc>uy){
      if(p1<0.7)dc[s]=1;
      if(p1>0.7)dy[s]=-1;
      }
        if(uy>uc){
      if(p1<0.7)dy[s]=-1;
      if(p1>0.7)dc[s]=1;
        }
 
    }
 
    void spin_b(int s){
 
      double uc,uy;
      uc=u(c[s]+1,y[s],th)-u(c[s],y[s],th);
      uy=u(c[s],y[s]-1,th)-u(c[s],y[s],th); 
 
      dc[s]=0;
      dy[s]=0;
 
 
        double p1;
 
        p1=Math.random();
 
      if(uc>uy){
      if(p1<0.7)dy[s]=1;
      if(p1>0.7)dc[s]=-1;
      }
        if(uy>uc){
      if(p1<0.7)dc[s]=-1;
      if(p1>0.7)dy[s]=1;
        }
 
    }
 
    double u(int c1,int y1,int th1){
 
        double delta,u1;
        delta=0.01;
 
        u1=Math.log(c1*delta)+Math.log(1-(double)y1/th1);
        return u1;
    }
    int avgmet(int s){
 
        int c1,y1,m1;
 
       c1=c[s]-avg_c;
    y1=y[s]-avg_y;
 
    m1=(int)(Math.sqrt(c1*c1+y1*y1));    
 
    return m1;
    }
   int minmet(int s){
    int sx,m1,minm;
       minm=999;
        for(sx=1;sx<101;sx++){
        m1=met(s,sx);
        if(s==sx)m1=999;
        if(m1<minm)minm=m1;
        }
 
    return minm;
 
    }
 
    int met(int s1,int s2){
 
        int c1,y1,m1;
    c1=c[s1]-c[s2];
    y1=y[s1]-y[s2];
 
    m1=(int)(Math.sqrt(c1*c1+y1*y1));    
 
    return m1;
 
    }
 
    int bud(){
    int b1,s;
        b1=0;
        for(s=1;s<101;s++){
        b1=b1+y[s]-c[s];
        }
    return b1;
    }
  void avg(){ 
 
   avg_c=0;
   for(s=1;s<101;s++){ 
   avg_c=c[s]+avg_c;
   }
   avg_c=avg_c/100;
 
   avg_y=0;
   for(s=1;s<101;s++){ 
   avg_y=y[s]+avg_y;
   }
   avg_y=avg_y/100;
 
 
  }
void move(){
 
for(s=1;s<101;s++){    
c[s]=c[s]+dc[s];
y[s]=y[s]+dy[s];
}
 
for(s=1;s<101;s++){    
c[s]=rev(c[s]);
y[s]=rev(y[s]);
}
 
}
int rev(int n){
int n1;
n1=n;
if(n1<0)n1=0;    
if(n1>th-1)n1=th-1;      
return n1;    
}
}
最終更新:2014年04月27日 04:36