Pagini recente » Cod sursa (job #3121542) | Cod sursa (job #2375647) | Cod sursa (job #3275347) | Cod sursa (job #2506102) | Cod sursa (job #2753093)
#include <bits/stdc++.h>
using namespace std;
ifstream fin( "patrate3.in" );
ofstream fout( "patrate3.out" );
double err = 0.00001;
int cnt = 0;
unordered_map <int, vector< pair<double, double> > > H;
int HashF( double x, double y ) {
return x;
}
bool Check_points( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4 ) {
return ( abs( x1 + x2 - x3 - x4 ) < err && abs( y1 + y2 - y3 - y4 ) < err );
}
void Check( double x1, double y1, double x2, double y2 ) {
double x3, y3, x4, y4;
double C;
C = x1 + x2 - abs( y1 - y2 );
x3 = C / 2;
x4 = x3 + abs( y1 - y2 );
C = y1 + y2 - abs( x1 - x2 );
y3 = C / 2;
y4 = y3 + abs( x1 - x2 );
if( !Check_points( x1, y1, x2, y2, x3, y3, x4, y4 ) )
swap( y3, y4 );
//fout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
//fout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << '\n';
int hf = HashF( x3, y3 );
for( int i = 0; i < H[hf].size(); ++i )
if( abs( H[hf][i].first - x3 ) < err && abs( H[hf][i].second - y3 ) < err ) {
//fout << H[hf][i].first << ' ' << H[hf][i].second << '\n';
++cnt;
break;
}
hf = HashF( x4, y4 );
for( int i = 0; i < H[hf].size(); ++i )
if( abs( H[hf][i].first - x4 ) < err && abs( H[hf][i].second - y4 ) < err ) {
++cnt;
break;
}
}
int main()
{
int N;
vector <pair<double, double> > V;
fin >> N;
for( int i = 1; i <= N; ++i ) {
double x, y;
fin >> x >> y;
x += 10001;
y += 10001;
V.push_back( { x, y } );
H[x].push_back( { x, y } );
}
for( int i = 0; i < V.size(); ++i )
for( int j = i + 1; j < V.size(); ++j )
Check( V[i].first, V[i].second, V[j].first, V[j].second );
//Check( V[0].first, V[0].second, V[8].first, V[8].second );
fout << cnt / 2 << '\n';
return 0;
}