Cod sursa(job #1972973)

Utilizator sichetpaulSichet Paul sichetpaul Data 24 aprilie 2017 09:32:11
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
struct punct {
  double x,y;
};
 punct v[1001];
bool compar(punct a,punct b) {
    if (a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}
 int n;
bool bin(double xc,double yc) {
  int st=1,dr=n,mij;
   while (st<=dr) {
     mij=(st+dr)/2;
     if (v[mij].x==xc && v[mij].y==yc) return 1;
     if ((v[mij].x==xc && v[mij].y<yc) || v[mij].x<xc) st=mij+1;
      else dr=mij-1;
    }
     return 0;
}
int main()
{ int i,x_mid,y_mid,difx,dify,nr=0,j;
    ifstream f("patrate3.in");
    ofstream g("patrate3.out");
    f>>n;
    for (i=1;i<=n;++i) {
       f>>v[i].x>>v[i].y;
       v[i].x=round(v[i].x*10000);
       v[i].y=round(v[i].y*10000);
    }
      sort(v+1,v+n+1,compar);
      for (i=1;i<n;++i)
      for (j=i+1;j<=n;++j) {
         x_mid=(v[i].x+v[j].x)/2;
         y_mid=(v[i].y+v[j].y)/2;
         difx=x_mid-v[i].x;
         dify=y_mid-v[i].y;
         if (bin(x_mid-dify,y_mid+difx)==1 && bin(x_mid+dify,y_mid-difx)==1)
                ++nr;
      }
        g<<nr/2<<'\n';
    return 0;
}