Pagini recente » Cod sursa (job #1932287) | Cod sursa (job #1002362) | Cod sursa (job #2686071) | Cod sursa (job #1577485) | Cod sursa (job #1625286)
/**
* Code by Patrick Sava
* "Spiru Haret" National College of Bucharest
**/
# include "fstream"
# include "cstring"
# include "vector"
# include "queue"
# include "bitset"
# include "algorithm"
# include "map"
# include "set"
# include "unordered_map"
# include "deque"
# include "string"
# include "iomanip"
# include "cmath"
# include "stack"
# include "cassert"
const char IN [ ] = "patrate3.in" ;
const char OUT [ ] = "patrate3.out" ;
using namespace std ;
# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( register int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( register int a = b ; a >= c ; -- a )
ifstream cin ( IN ) ;
ofstream cout ( OUT ) ;
const int MAX = 1e3 + 14 ;
struct pp {
double x , y ;
} p [ MAX ] ;
const double EPS = 0.0001 ;
struct cmp {
bool operator ( ) ( const pp &a , const pp &b ) const
{
if ( fabs ( a.x - b.x ) < EPS )
return a.y - b.y < - EPS ;
return a.x - b.x < - EPS ;
}
};
const double PI = 3.1415926535897932384626433832795 ;
int n ;
int bs ( double a , double b )
{
int st = 1 ;
int dr = n ;
while ( st <= dr )
{
int mij = ( st + dr ) >> 1 ;
if ( p [ mij ].x - a > EPS ) {
dr = mij - 1 ;
}
else if ( p [ mij ].x - a < -EPS ) {
st = mij + 1 ;
}
else {
if ( p [ mij ].y - b < -EPS ) {
st = mij + 1 ;
}
else if ( p [ mij ].y - b > EPS ) {
dr = mij - 1 ;
}
else {
//cout << a.x << ' ' << a.y << '\n' ;
return 1 ;
}
}
}
return 0 ;
}
int main()
{
cin >> n ;
FORN ( i , 1 , n )
cin >> p [ i ].x >> p [ i ].y ;
sort ( p + 1 , p + n + 1 , cmp ( )) ;
double angle ;
double angle2 ;
double xx1 , yy1 , xx2 , yy2 ;
double a , b , c , d ;
int sol = 0 ;
double panta ;
double cc , ss ;
FORN ( i , 1 , n )
{
FORN ( j , i + 1 , n )
{
panta = ( p [ i ].y - p [ j ].y ) / ( p [ i ].x - p [ j ].x ) ;
//cout << panta << '\n' ;
angle = PI / 4.0 - atan ( panta ) ;
cc = cos ( angle ) ;
ss = sin ( angle ) ;
xx1 = cc * p [ i ].x - ss * p [ i ].y ;
yy1 = ss * p [ i ].x + cc * p [ i ].y ;
xx2 = cc * p [ j ].x - ss * p [ j ].y ;
yy2 = ss * p [ j ].x + cc * p [ j ].y ;
angle2 = - angle ;
//cout << atan ( panta ) << '\n' ;
//return 0 ;
///cout << angle2 << '\n' ;
cc = cos ( angle2 ) ;
ss = sin ( angle2 ) ;
a = cc * xx1 - ss * yy2 ;
b = ss * xx1 + cc * yy2 ;
c = cc * xx2 - ss * yy1 ;
d = ss * xx2 + cc * yy1 ;
//int aux = bs ( mp ( a , b ) ) ;
//int aux2 = bs ( mp ( c , d ) ) ;
if ( bs ( a , b ) and bs ( c , d ) ){
++ sol ;
}
//cout << cos ( angle ) << '\n' ;
//cout << sin ( angle ) << '\n' ;
//return 0 ;
// cout << a << ' ' << b << '\n' ;
// cout << c << ' ' << d << '\n' ;
//cout << endl ;
//cout << endl ;
//cout << endl ;
}
}
cout << sol / 2 << '\n' ;
return 0;
}