2 3 1 1 2 2 3 3 4 0 0 1 0 0 1 1 1
1 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-6)
#define inf (1<<28)
#define sqr(x) (x) * (x)
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<ll,ll> p;
map<p,ll> m;
struct point
{
ll x,y;
}a[1005];
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
bool cmp(point a,point b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
ll i,j,k,n,t;
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d",&n);
for(i=0;i<n;i++)
scanf("%I64d%I64d",&a[i].x,&a[i].y);
sort(a,a+n,cmp);
ll ans=0;
for(i=0;i<n;i++)
{
m.clear();
for(j=i+1;j<n;j++)
{
ll dx=a[j].x-a[i].x;
ll dy=a[j].y-a[i].y;
ll d=gcd(dx,dy);
dx=dx/d;
dy=dy/d;
m[make_pair(dx,dy)]++;
}
map<p,ll>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
k=it->second;
if(k>=2)
ans=ans+k*(k-1)/2;
}
}
printf("%I64d\n",ans);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5020 Revenge of Collinearity(枚举)
原文:http://blog.csdn.net/yanghuaqings/article/details/47323233