我已经开始构建这样的东西:
class Node{
Node next,prev;
int val;
Node(int val, Node prev, Node next){
this.val = val;
this.prev = prev;
this.next = next;
}
}
……
public void buildRandomPath(int size, int total){
road = new Node[size];
int tmp = (int)(Math.random()*(double)(total/size));
total = total-tmp;
road[0] = new Node(tmp,road[size-1],road[1]);
for (int i = 1; i < size-1; i++){
tmp = (int)(Math.random()*(double)(total/size-i));
total = total-tmp;
road[i] = new Node(tmp1,road[i-1],road[i+1]);
}
tmp = (int)(Math.random()*(double)(total));
total = total-tmp;
road[size-1] = new Node(tmp,road[size-2],road[0]);
}
这完全不是正确的算法,但这是我的总体思路