Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2D dynamic bool array?

Name: Anonymous 2006-01-03 16:44

I want to create a 2D dynamic bool array (or char is fine too). I'm doing the n-queens problem and I've figured everything out except for this part. Any help?

Name: Anonymous 2006-01-11 17:04

orz...I wasted too much time on this. Not that the original poster would understand this... Not that I tested this either.

int N = 5;
int cities[N] = {5,3,2,6,7};
int *distances;

int sum (int a, int b) { return ((b*(b+1) - a*(a-1))/2); }

int index (int a, int b) { return (a*N - a*(a+1)/2 - 1 + b); }

int distance (int a, int b) { return (a==b ? 0 : distances[index(a,b)]); }

void make_distances (int a, int b) {
  distances = malloc (sum(a,b));

  int i=0,acc;
  for (a=0; a++; a<N) {
    acc = cities[a];
    for (b=a+1; b++; b<=N) {
      distances[i] = acc;
      acc += cities[b];
    }
  }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List