diff --git a/src/cowtour/cowtour/main.cpp b/src/cowtour/cowtour/main.cpp index eef2896..7b7e57d 100644 --- a/src/cowtour/cowtour/main.cpp +++ b/src/cowtour/cowtour/main.cpp @@ -14,77 +14,63 @@ #include using namespace std; /* - The strategy is that I am first going to do Bellman-Ford, I am going to take the size of the array which means going to run through this n times. Because at most a certain point would be n points away from the current point you are at - to run through everything so for each one of the iterations it goes through every element in the 2d array, so then let's say - I'm at an element [x][y] that means that point x [x][j] distance away from y, so then I got to the [y] column of the 2d - array then I go through the entire column and then I i make the column [x] equal to [i] that is my algorithim for figuring - out the shortest path to it. I do this to find the shortest one, like from point i to point k may be slower than from point - i to point j to point k, it also allows me to figure out all the places that I haven't been to from that point. - - After I figure out the shortest path to everything I got through each element of the 2d array that is infinity, I want to - find the points that can't be connected and then I find the longest distance that I can go from each point, So i find the - farthest distance from point I and then I find the farthest distance from point j, this means that if I connect these two - points, the farthest will be the edges and the diameter would be the two farthest points plus the distance between I and J. - I then compare it with the maximum diamter of the field I vs the diiamter of field J and I find the max between the max - diamter and the connected points - + First use one sentence to describe the highlevel plan, then go into the details. That will + it easy for people to follow. + + The strategy is that I am first going to do Bellman-Ford, I am going to take the size of the + array which means going to run through this n times. Because at most a certain point would be + n points away from the current point you are at to run through everything so for each one of + the iterations it goes through every element in the 2d array, so then let's say + I'm at an element [x][y] that means that point x [x][j] distance away from y, so then I got + to the [y] column of the 2d array then I go through the entire column and then I i make the + column [x] equal to [i] that is my algorithim for figuring out the shortest path to it. + I do this to find the shortest one, like from point i to point k may be slower than from point + i to point j to point k, it also allows me to figure out all the places that I haven't been + to from that point. + After I figure out the shortest path to everything I got through each element of the 2d array + that is infinity, I want to find the points that can't be connected and then I find the longest + distance that I can go from each point, So i find the farthest distance from point I and then + I find the farthest distance from point j, this means that if I connect these two points, + the farthest will be the edges and the diameter would be the two farthest points plus the + distance between I and J. I then compare it with the maximum diamter of the field I vs the + diiamter of field J and I find the max between the max diamter and the connected points */ class object { public: int first; int second; - object(){ - first = 0; - second = 0; - } + object(int x, int y) : first(x), second(y) {} }; -object newobj(int first, int second){ - object n; - n.first = first; - n.second = second; - return n; -} - -int connect(vector x){ - return 0; -} - -double getdis(object n, object k){ +double getdis(const object& n, const object& k){ return sqrt((n.first-k.first)*(n.first-k.first)+(n.second-k.second)*(n.second-k.second)); } + void map(vector >& x){ //if (k >= m.size()) std::cerr << "error" << endl; - - for(int k = 0; k >& x){ int main(int argc, const char * argv[]) { - // insert code here... - //cout<<"yo \n"; - ofstream fout ("cowtour.out"); - //fout<< "yo"; - //fout.cose(); - ifstream fin ("cowtour.in"); int k; - fin>>k; - vector coord; - vector > stuff(k, vector(k, -1)); - /* - object n; - n.first = 1; - n.second = 1; - object so; - so.first=2; - so.second =2; - cout<> k; + vector vertex; + for(int i = 0; i < k; i++){ int x, y; - object obj; fin>>x>>y; - obj.first = x; - obj.second = y; - coord.push_back(obj); + vertex.push_back(object(x, y)); } - - - for(int i = 0; i > distance(k, vector(k, -1)); + for(int i = 0; i < k; i++){ string s; - fin>>s; - for(int j = i; j> s; + for(int j = i; j < k; j++){ if(i==j){ - stuff[i][j] = 0; + distance[i][j] = 0; } - if(s[j]!='0'){ - stuff[i][j] = getdis(coord[i],coord[j]); - stuff[j][i] = getdis(coord[i],coord[j]); + if(s[j] != '0'){ + distance[i][j] = getdis(vertex[i], vertex[j]); + distance[j][i] = getdis(vertex[i], vertex[j]); } } } - for(int i = 0;i all; @@ -149,8 +114,8 @@ int main(int argc, const char * argv[]) { for(int i = 0;imax){ - max = stuff[i][j]; + if(distance[i][j]>max){ + max = distance[i][j]; } } all.push_back(max); @@ -160,7 +125,7 @@ int main(int argc, const char * argv[]) { for(int i = 0; imax){ max = all[j]; } @@ -169,34 +134,25 @@ int main(int argc, const char * argv[]) { diameter[i] = max; } double min = -1.0; - for(int i = 0; i maxj+maxi+getdis(coord[i], coord[j])){ + }else if( min > maxj+maxi+getdis(vertex[i], vertex[j])){ - min = max(maxj+maxi+getdis(coord[i], coord[j]), max(diameter[i],diameter[j])); + min = max(maxj+maxi+getdis(vertex[i], vertex[j]), max(diameter[i],diameter[j])); } } } } - object n; - n.first = 0; - n.second = 0; - object so; - so.first=1; - so.second =0; - fout<