Cod sursa(job #774952)

Utilizator ionut_blesneagIonut Blesneag ionut_blesneag Data 6 august 2012 20:03:48
Problema Patrate 3 Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include<fstream>
const int hmax=93939;
using namespace std;

ifstream f("patrate3.in");
ofstream g("patrate3.out");
int verif,nrsquare,xplan1,xplan2,yplan1,yplan2;
struct hash{
int point;
hash *next;};

hash* hsh[hmax];

int n,i,j,nrc;
char buff[40];
long x[1001],y[1001];
int xa,xb,ya,yb;


int get_number()
{long nr=0;
int ng=1;
if(buff[nrc]=='-')
  {ng=-1; nrc++;}
while(buff[nrc]>='0' && buff[nrc]<='9')
  {nr=nr*10+buff[nrc]-'0';
   nrc++;
   if(buff[nrc]=='.')
      nrc++;}
nr*=ng;      
return nr;            
}

void add(int jj, int a, int b)
{long long chi;
 int psi;
 chi=93*a+b;
 if(chi<0)
   chi=chi*(-1);
psi=chi%hmax;
hash* q=new hash;
q->point=jj;
q->next=hsh[psi];
hsh[psi]=q;
}

void search(int a, int b)
{long long chi;
 int jj;
 int psi;
 chi=93*a+b;
  if(chi<0)
   chi=chi*(-1);
psi=chi%hmax;
hash* q=hsh[psi];
while(q)
{jj=q->point;
 if(x[jj]==a && y[jj]==b)
       verif++;
 q=q->next;}
}

int main()
{f>>n;
f.getline(buff,40);
for(i=1; i<=n; i++)
{f.getline(buff,40);
 nrc=0;
 x[i]=get_number();
 nrc++;
 y[i]=get_number();
 add(i,x[i],y[i]);}

nrsquare=0;
for(i=1; i<=n; i++)
  for(j=i+1; j<=n; j++)
  {if(y[i]>y[j])
      {xa=x[j];   ya=y[j];  
       xb=x[i];   yb=y[i];} 
    else
       {xa=x[j];   ya=y[j];  
       xb=x[i];   yb=y[i];} 
     
     yplan1=ya-(xb-xa);
     yplan2=yb-(xb-xa);
     
     xplan1=xa+(yb-ya);
     xplan2=xb+(yb-ya);
     
     verif=0;
     search(xplan1,yplan1); 
     search(xplan2,yplan2);
     if(verif==2)
       nrsquare++;
  }           
g<<nrsquare/2;  
f.close();
g.close();
return 0;}