Title Description
There on the plane n n coordinate disparate point, may I ask how many of the group's three non-collinear points, three points circumcenter also in this n in n points?
Enter a description
The first line has a positive integer n representative of n points in the plane.
Then there are n- n-row, among the first i i line contains two integers x_i, y_i, X i , Y i represents the i coordinate points is (x_i, y_i) ( X i , Y i ) .
1<=n<=2000
-10^9<=x,y<=10^9
!! If i = j, then (xi, yi) = (xj, yj);
Sample input
5 0 0 -2 0 0 2 -1 1 2 0
Sample Output
2
When to get this title, thinking about violence, but involves four for, so a timeout. There is no time to engage in out of the game, is very regrettable. Once on shore, watching AC codes of others, and suddenly!
If the distance from a point to the other three points are equal, then this is certainly not the three points are collinear, so this does not need to manage a fundamentally, go directly from a point to another point a1, the number of occurrences with a map from the recording , if the number of occurrences of a certain distance K> = 3 is present, a1 is the circumcenter these points, due to the number of combinations is selected, it can be a CK 3, three of which are selected from the group of the number of occurrences, so CK 3 .
There are also map iterators wording, always forget
#include<cstring> #include<iostream> #include<map> #include<algorithm> using namespace std; const int maxn = 2e3+10; typedef long long ll; ll num[maxn]; struct node { ll x,y; }st[maxn]; ll distance(ll x1,ll y1,ll x2, ll y2) { return ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { int n ; cin>>n; for(int i = 0 ; i< n ; i++) { cin>>st[i].x>>st[i].y; } ll sum = 0 ; for(int i = 0 ; i <n ;i ++) { map<ll,ll>mm; for(int j = 0 ; j<n ; j++) { if(i!=j) { ll s=distance(st[i].x,st[i].y,st[j].x,st[j].y); // cout<<s<<endl; mm[s]++; } }
map<ll,ll>::iterator it; //遍历map写法
for(it = mm.begin();it!=mm.end();it++) { if(it->second>=3) { ll k = it->second; // cout<<k<<endl; sum+=k*(k-1)*(k-2)/6; //C k 3 } } } cout<<sum<<endl; return 0; }