Simple GIS

GISプログラムの練習

グループの練習

package group;


public class pro {

    int f=new int[101][101];
    int m,n,s;
  int teamx=new int[10000];
  int teamy=new int[10000];
  int teamnumber;
int group=new int[10000];
int groupnumber=new int[10000];  
int tx,g;
  
    public static void main(String[] args) {
        pro test=new pro();
    }
pro(){

    shuffle();

    maketeam();
    
    group();
    
    System.out.println(teamnumber);
System.out.println(g);
    
    
}
void group(){
int mode;
g=1;
s=fastgroup();
group[s]=g;
groupnumber[g]=1;
makegroup(g); 
mode=0;    
while(mode<50){
g=g+1;
s=fastgroup();
if(s>0){
group[s]=g;
groupnumber[g]=1; 
makegroup(g);
}
if(s==0)mode=100;
}
g=g-1;
}

int fastgroup(){
int tx,txs,h;
txs=0;
for(tx=1;tx<teamnumber+1;tx++){
   h=0;
    if(group[tx]==0)h=h+1;
    if(txs==0)h=h+1;
    if(h==2)txs=tx;
    }
return txs;

}

void makegroup(int g){
int sx,mode;
sx=0;
mode=0;
while(mode<50){
sx=sx+1;
check(sx);
if(sx==groupnumber[g])mode=100;
}

}
void check(int s){
int tx,h,z;
    for(tx=1;tx<teamnumber+1;tx++){
    h=0;
z=(teamx[tx]-teamx[s])*(teamx[tx]-teamx[s])+(teamy[tx]-teamy[s])*(teamy[tx]-teamy[s]);
    if(z==1)h=h+1;
    if(group[tx]==0)h=h+1;
    if(h==2)groupnumber[g]=groupnumber[g]+1;
    if(h==2)group[tx]=g;
    }
    
}


int met(int s1,int s2){
int x1,y1,x2,y2,z1;
x1=teamx[s1];
y1=teamy[s1];
x2=teamx[s2];
y2=teamy[s2];
z1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
return z1;
}


void shuffle(){

    for(m=1;m<101;m++){
     for(n=1;n<101;n++){
         f[m][n]=0;
    if(Math.random()>0.5)f[m][n]=100; 
     }
     }
    
    
}
void maketeam(){
s=0;
  for(m=1;m<101;m++){
     for(n=1;n<101;n++){
     if(f[m][n]>50)s=s+1;
       if(f[m][n]>50)teamy[s]=m;
        if(f[m][n]>50)teamx[s]=n;
     }
     }
    teamnumber=s;
    
    
}
    

}