转载自http://www.codeweblog.com/snake-algorithm-java-implementation/#
public class test {
/**
* Describes a :
* 5 Line 5 column snake-like algorithm
* (0,0)(4,4)- Line 1 and countdown 1 Difference between rows 4
* (1,0)(4,3)(0,1)(3,4)- Line 2 and countdown 2 Difference between rows 3
* (0,2)(2,4)(1,1)(3,3)(2,0)(4,2)- The first 3 rows and countdown 3 Difference between rows 2
* (3,0)(4,1)(2,1)(3,2)(1,2)(2,3)(0,3)(1,4)- The fourth row and countdown 4 Difference between rows 1
* Section 5 behavior segmentation line
* According to the above description, obtain the following algorithm
*/
/**
* Description of second :
* dao Variable functions :
* The main calculation downward diagonal coordinate values .
* For example, :5 Line 5 columns
* {
(0,0) -- Known as line 0
(1,0)(0,1) -- Known as line 1
(0,2)(1,1)(2,0) -- Known as line 2
(3,0)(2,1)(1,2)(0,3) -- Known as line 3
}--- All coordinates on the diagonal
(0,4)(1,3)(2,2)(3,1)(4,0)--- Here called diagonal 4
{
(4,1)(3,2)(2,3)(1,4) -- Known as line 5
(2,4)(3,3)(4,2) -- Known as line 6
(4,3)(3,4) -- Known as line 7
(4,4) -- Known as line 8
}--- Downward diagonal all coordinates
dao The maximum value of the variable is line * Column
Get all the coordinates of the diagonal values by dao variables and temp Variable functions
*/
/**
* @param irow Line
* @param icol Column
* @param sheLength Sections snake segment, which is line with diagonal
*/
public void sheAglo(int irow,int icol,int sheLength){
int row = 0,col = 0;
int ban = (sheLength-1)/2+1;
int array[][] = new int[irow][icol];
int m = 1,num = ban - 1;
int dao = irow*icol;
for(int i=0;i<ban;i++){
row = col = i;
int temp = dao-i;// The first n rows downward diagonal values from dao-i Start
if(i%2==0){ // Handling double-row
/**
* (0,0)
* (0,2)(1,1)(2,0)
* Characteristic is the increment, decrement column rows
*/
while(col>=0){
System.out.print("["+(i-col)+"]["+(col)+"]("+m+"),");
if(i!=ban-1){// This is the diagonal
System.out.print("["+(i-col+num)+"]["+(col+num)+"]("+(temp++)+"),");
}
array[i-col][col] = m;
dao--;
col--;
m++;
}
}else if(i%2!=0){// Handle single-line
/**
* (1,0)(0,1)
* (3,0)(2,1)(1,2)(0,3)
* Characteristics are diminishing, incrementing column rows
*/
while(row>=0){
System.out.print("["+(row)+"]["+(i-row)+"]("+m+"),");
if(i!=ban-1){
System.out.print("["+(row+num)+"]["+(i-row+num)+"]("+(temp++)+"),");
}
array[row][i-row] = m;
dao--;
row--;
m++;
}
}
num--;
System.out.println();
}
}
public static void main(String args[]){
test test = new test();
test.sheAglo(6,6,11);
}
}
另外一个重要网站:http://users.ecs.soton.ac.uk/msn/book/new_demo/Snakes/
分享到:
相关推荐
蛇形图像分割算法,主动轮廓边界提取算法。
Algorithm-algorithm-implementation-in-java-javascript-scala.zip,本项目的目标是提供Java、JavaScript和斯卡拉的可重用算法集合。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Recurrent Reinforcement Learning Algorithm Matlab Implementation.zip
介绍Levenberg-Marquardt算法实现的资料,现在大部分软件都用这篇文章的实现方法!
Binary division algorithm and implementation in VHDL
SNAKE算法代码,图像处理,matlab程序。
Genetic Algorithm Implementation Using Matlab
snake的经典算法,应用于图像分割,效果很好
java算法大全,非常实用,讲解非常清晰,易懂易学
algorithm-essentials-java
Genetic Algorithm Implementation
data structure and algorithm, java. 中文版
Algorithm-java-algorithms-implementation.zip,Java实现的算法和数据结构,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
用python來實現遺傳算法的一篇文章 genetic algorithm implementation in python
distance vector algorithm implementation in C. you can simulate router using local device's ports. Makefile is included for UNIX/LINUX users.
AES algorithm implementation in C
K-best Schnorr–Euchner (KSE) decoding algorithm is proposed in this paper to approach near-maximum-likelihood (ML) performance for multiple-input–multiple-output (MIMO) detection.
使用java语言实现匈牙利算法。可实现任务最优分配,以及旅行商问题