SuitNdtie

Valentine Plan

Mar 29th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. typedef struct{
  6.     double x;
  7.     double y;
  8. }pos;
  9.  
  10. double dist(pos a,pos b){
  11.     return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
  12. }
  13.  
  14. int main()
  15. {
  16.     int n,m;
  17.     scanf("%d %d",&n,&m);
  18.     pos male[n];
  19.     pos female[m];
  20.     for(int i=0;i<n;i++){
  21.         scanf("%lf %lf",&male[i].x,&male[i].y);
  22.     }
  23.     for(int i=0;i<m;i++){
  24.         scanf("%lf %lf",&female[i].x,&female[i].y);
  25.     }
  26.     double mindist = 2e9;
  27.     for(int i=0;i<n;i++){
  28.         for(int j=0;j<m;j++){
  29.             if(dist(male[i],female[j]) < mindist){
  30.                 mindist = dist(male[i],female[j]);
  31.             }
  32.         }
  33.     }
  34.     printf("%.3lf",mindist);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment