Pagini recente » Cod sursa (job #653220) | Cod sursa (job #800197) | Cod sursa (job #2693724) | Cod sursa (job #854994) | Cod sursa (job #1763715)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#define MOD 666013
#define MAXN 1000
#define BUF_SIZE 16384
char buf[BUF_SIZE];
int pbuf=BUF_SIZE;
FILE*fi,*fo;
inline char nextch(){
if(pbuf==BUF_SIZE){
fread(buf, BUF_SIZE, 1, fi);
pbuf=0;
}
return buf[pbuf++];
}
inline long long nextnum(){
long long a=0;
char c=nextch();
while((c<'0' || c>'9') && c!='-')
c=nextch();
int semn=1;
if(c=='-'){
semn=-1;
c=nextch();
}
while(('0'<=c && c<='9') || c=='.'){
if(c!='.')
a=a*10+c-'0';
c=nextch();
}
return a*semn;
}
class Hash{
public:
long long k=0, next[MAXN+1], *lista;
long long val[MAXN+1];
long long d[MAXN+1];
Hash() {
lista = new long long[MOD];
memset(lista, 0x00, MOD*sizeof(int));
}
inline void insert(long long x, long long y, long long frecventa){
k++;
val[k]=y;
d[k]=frecventa;
next[k]=lista[(1LL*x+1LL*MOD*MOD)%MOD];
lista[(1LL*x+1LL*MOD*MOD)%MOD]=k;
}
inline void erase(long long element){
long long p=lista[(1LL*element+1LL*MOD*MOD)%MOD];
if(p==0)
return ;
if(val[p]==element){
lista[(1LL*element+1LL*MOD*MOD)%MOD]=next[lista[(1LL*element+1LL*MOD*MOD)%MOD]];
return ;
}
while(next[p]!=0 && val[next[p]]!=element)
p=next[p];
if(next[p]!=0){
next[p]=next[next[p]];
}
}
inline long long find(long long x, long long y){
long long p=lista[(1LL*x+1LL*MOD*MOD)%MOD];
while(p!=0 && val[p]!=y)
p=next[p];
if(p!=0)
return p;
return 0;
}
} H;
struct Point{
int x, y;
}v[MAXN+1];
inline int M(Point A, Point B){
if(A.y>B.y)
return 1;
if(A.y==B.y && A.x>B.x)
return 1;
return 0;
}
inline int m(Point A, Point B){
if(A.y<B.y)
return 1;
if(A.y==B.y && A.x<B.x)
return 1;
return 0;
}
void q(int begin, int end){
int b=begin, e=end;
Point p=v[(b+e)/2];
while(b<=e){
while(m(v[b], p)) b++;
while(M(v[e], p)) e--;
if(b<=e){
Point aux=v[b];
v[b]=v[e];
v[e]=aux;
b++;
e--;
}
}
if(b<end) q(b, end);
if(begin<e) q(begin, e);
}
int main(){
fi=fopen("patrate3.in","r");
fo=fopen("patrate3.out","w");
int n=nextnum();
for(int i=1;i<=n;i++){
v[i].x=nextnum();
v[i].y=nextnum();
}
q(1, n);
int squares=0;
for(int i=1;i<=n;i++)
H.insert(v[i].x, v[i].y, 1);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++){
if(v[i].x>v[j].x){
//printf("%lld %lld", H.find(v[i].x-(v[i].y-v[j].y), v[i].y-(v[j].x-v[i].x)), H.find(v[j].x-(v[i].y-v[j].y), v[j].y-(v[j].x-v[i].x)));
if(H.find(v[i].x-(v[i].y-v[j].y), v[i].y+(v[i].x-v[j].x)) && H.find(v[j].x-(v[i].y-v[j].y), v[j].y+(v[i].x-v[j].x)))
squares++;
if(H.find(v[i].x+(v[i].y-v[j].y), v[i].y-(v[i].x-v[j].x)) && H.find(v[j].x+(v[i].y-v[j].y), v[j].y-(v[i].x-v[j].x)))
squares++;
}
else{
if(H.find(v[i].x+(v[i].y-v[j].y), v[i].y+(v[j].x-v[i].x)) && H.find(v[j].x+(v[i].y-v[j].y), v[j].y+(v[j].x-v[i].x)))
squares++;
if(H.find(v[i].x-(v[i].y-v[j].y), v[i].y-(v[j].x-v[i].x)) && H.find(v[j].x-(v[i].y-v[j].y), v[j].y-(v[j].x-v[i].x)))
squares++;
}
}
fprintf(fo,"%d", squares/4);
fclose(fi);
fclose(fo);
return 0;
}