Cod sursa(job #1048262)

Utilizator the@EyE@Postavaru Stefan the@EyE@ Data 5 decembrie 2013 18:22:32
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.71 kb
#include<stdio.h>
#include<unordered_set>
#include<math.h>
#include<vector>

using namespace std;

struct point
{
    double x,y;
};

unordered_set<long long> hash_points;

vector<point> points;
int n,ras=0;

long long getHash(point p)
{
    return (long long)((p.x+10000)*10000*1000000000+(p.y+10000)*10000);
}

double dx[]={0.0001,-0.0001};

void roundDouble(double &n)
{
    double t;
      t=n-floor(n);
      if (t>=0.5)
      {
        n*=10000;
        ceil(n);
        n/=10000;
      }
      else
      {
        n*=10000;//where n is the multi-decimal float
        floor(n);
        n/=10000;
      }
}

int main()
{
    freopen("patrate3.in","r",stdin);
    freopen("patrate3.out","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        point p;
        scanf("%lf%lf",&p.x,&p.y);
        hash_points.insert(getHash(p));
        points.push_back(p);
        for(int k=0;k<2;++k)
            for(int j=0;j<2;++j)
            {
                point p2;p2.x=p.x+dx[k];p2.y=p.y+dx[j];
                hash_points.insert(getHash(p2));
            }
    }
    for(int i=0;i<n-1;++i)
        for(int j=i+1;j<n;++j)
        {
            point p1=points[i];point p2=points[j];
            double dy=fabs(p1.y-p2.y)/2;double cy=(p1.y+p2.y)/2;
            double dx=fabs(p1.x-p2.x)/2;double cx=(p1.x+p2.x)/2;
            point p3;p3.x=cx-dy;p3.y=cy-dx;
            roundDouble(p3.x);roundDouble(p3.y);
            point p4;p4.x=cx+dy;p4.y=cy+dx;roundDouble(p4.x);roundDouble(p4.y);
            if(hash_points.find(getHash(p3))!=hash_points.end()&&hash_points.find(getHash(p4))!=hash_points.end())ras++;
        }
    printf("%d\n",ras);

    return 0;
}