Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct
- {
- float x, y;
- }Point;
- typedef struct
- {
- Point a;
- Point b;
- }Section;
- float euclid(Section k)
- {
- return hypot(k.a.x - k.b.x, k.a.y - k.b.y);
- //return sqrt(pow(k.a.x-k.b.x,2)+pow(k.a.y-k.b.y,2));
- }
- float city(Section k)
- {
- return fabs(k.a.x - k.b.x) + fabs(k.a.y - k.b.y);
- }
- float river(Section k)
- {
- if (k.a.x == k.b.x) return fabs(k.a.y - k.b.y);
- else return fabs(k.a.y) + fabs(k.a.x - k.b.x) + fabs(k.b.y);
- }
- Section shortest(Point arr[], int n, float(*fun)(Section))
- {
- float dist;
- float mindist=FLT_MAX;
- Section mins;
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- Section s = { arr[i],arr[j] };
- dist = fun(s);
- if (dist < mindist)
- {
- mindist = dist;
- mins = s;
- }
- }
- }
- return mins;
- }
- void kolos1()
- {
- Point arr[4] = { {1,2},{5,8},{-4,6},{-20,3} };
- Section s = shortest(arr, 4, euclid);
- printf("%f %f %f %f", s.a.x, s.a.y, s.b.x, s.b.y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement