Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double distance(int x1, int y1, int x2, int y2){
- return sqrt(pow((x2-x1),2)+pow((y2-y1),2));
- }
- void mini_peri(double *x, double *y, int len, double *rx, double *ry){
- double dist, currMin = 10e9;
- for(int i=0;i<len-2;i++){
- for(int j=i+1;j<len-1;j++){
- for(int k=j+1;k<len;k++){
- dist = distance(x[i],y[i],x[j],y[j]) + distance(x[i],y[i],x[k],y[k]) + distance(x[j],y[j],x[k],y[k]);
- if(dist<currMin){
- currMin = dist;
- rx[0] = x[i], ry[0] = y[i];
- rx[1] = x[j], ry[1] = y[j];
- rx[2] = x[k], ry[2] = y[k];
- }
- }
- }
- }
- }
- int main(){
- int n;
- while(scanf("%d", &n)){
- double *x = new double[n], *y = new double[n];
- double *minX = new double[3], *minY = new double[3];
- for(int i=0;i<n;i++){
- scanf("%lf %lf", &x[i], &y[i]);
- }
- mini_peri(x, y, n, minX, minY);
- for(int i=0;i<3;i++){
- printf("(%.1lf,%.1lf)", minX[i], minY[i]);
- if(i!=2){
- printf(", ");
- }
- }
- delete[] x, y, minX, minY;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement