Cod sursa(job #1303498)

Utilizator diana-t95FMI Tudoreanu Diana Elena diana-t95 Data 28 decembrie 2014 00:40:52
Problema Patrate 3 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
#define maxn 10001
#define mod 666013
#define err 10000
int n, answer=0;
vector<int> h[mod];
struct point
{
    int x, y;
};
point p[maxn];
int get_hash(point m)
{
    long long ans;
    ans=(long long)(m.x*m.y);
    if (ans<0) ans=-ans;
    ans=(int)(ans%mod);
    return (int)ans;
}
bool finder(point m)
{
    int hh=get_hash(m), i;
    for (i=0;i<h[hh].size();i++)
    {
    if (p[h[hh][i]].x==m.x && p[h[hh][i]].y==m.y) return true;
    }
    return false;
}
int main()
{
    FILE *f=fopen("patrate3.in", "r");
    ofstream g("patrate3.out");
    int i, j;
    point c, d, m;
    int a, b;
    fscanf(f, "%d\n",&n);
    for (i=0;i<n;i++)
    {
        fscanf(f, "%d.%d ", &a, &b);
        if (a>0) p[i].x=((a+1)*err+b)*10;
            else p[i].x=((a+1)*err-b)*10;
        fscanf(f, "%d.%d\n", &a, &b);
        if (a>0) p[i].y=((a+1)*err+b)*10;
            else p[i].y=((a+1)*err-b)*10;
        cout<<p[i].x<<' '<<p[i].y<<endl;
        h[get_hash(p[i])].push_back(i);
    }
    cout<<endl;
    cout<<endl;
    cout<<endl;
    for (i=0;i<n-1;i++)
        for (j=i+1;j<n;j++)
        {
               m.x=(p[i].x+p[j].x)/2;
               m.y=(p[i].y+p[j].y)/2;
               c.x=-(p[i].y-m.y)+m.x;
               c.y=(p[i].x-m.x)+m.y;
               d.x=(p[i].y-m.y)+m.x;
               d.y=-(p[i].x-m.x)+m.y;
               if (finder(c) && finder(d)) answer++;
        }
    answer=answer/2;
    g<<answer<<'\n';
}