That Italy: the plane of the points given n, q interrogation times, to a given time point P, Q n points in this plane and the point number right triangle can be composed, wherein (n + q) points equal to each other
Ideas:
Consider a point P at a right angle, respectively for non-right angle vertex and vertices. This question is very simple idea is to see how simple and does not tle! ! !
For the right-angled vertex and non-right angle vertex codes are relatively simple, which is a little off the idea of seeking.
Here is a map of the usage of say, less than custom operators, so that when looking at the map, the slope of the vector will be unified together, although a number of different vectors will still be stored in the map. (I heard that writing a scene of blood, Zhongshan University Gangster nb)
Algorithm complexity about n * n * log (n) (Due to the same range of n and p, where a uniform representation with n), the running time of about 10s
Code:
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 2005; struct P { ll x, y; P(ll xx=0, ll yy=0) { x = xx; y = yy; } P base()const{ if (x < 0 || (x == 0 && y < 0))return P(-x, -y); return *this; } BOOL operator <( const P & B) const { P P1 = Base ();. P2 = P B Base (); // if collinear, are considered the same index return P1.x p2.y * <p1.y * P2 .x; } P operator - ( const P & B) const { return P (X - BX, Y - by); } } A [N], Qur'an [N]; int n-, Q; Map <P, int > m; ANS LL [N]; int main () { the while (~ Scanf ( "%d%d", &n, &q)) { memset(ans,0,sizeof(ans)); for (int i = 0; i < n; i++)scanf("%lld%lld", &a[i].x, &a[i].y); for (int i = 0; i < q; i++)scanf("%lld%lld", &qur[i].x, &qur[i].y); for (int i = 0; i < q; i++) { //求解作为直角顶点 m.clear(); for( Int J = 0 ; J <n-; J ++ ) m [A [J] - Qur'an [I]] ++ ; for ( int J = 0 ; J <n-; J ++ ) { P P = A [J] - Qur'an [I]; P = P (- Py, PX); ANS [I] + = m.count (P) m [P]:? 0 ; } // Since the two right-angle sides are enumerated, so in addition to 2 ANS [I] / = 2 ; } for ( int I = 0 ; I <n-; I ++ ) { //As a non-right-angled vertex, each enumeration point i, as a right-angled vertex, all of the updated set of q interrogation points m.clear (); for ( int J = 0 ; J <n-; J ++ ) { IF (! I = J) m [A [J] - A [I]] ++ ; } for ( int J = 0 ; J <Q; J ++ ) { P P = Qur'an [J] - A [I]; P = P (- Py, PX); ANS [J] + = m.count (P) m [P]:? 0 ; } } for ( int I = 0 ; I <Q; I ++) the printf ("%lld\n", ans[i]); } return 0; }