原题:http://codeforces.com/problemset/problem/552/D
题意:
给出n个点,问一共可以形成多少个三角形;
思路:
直接暴力枚举,判断三个点是否共线;
当同个x的点有多个时,任意选择两个点都可以和其余的点构成三角形;
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int n;
vector<int>G[250];
int main()
{
scanf("%d", &n);
__int64 ans = 0;
for(int i = 0;i<n;i++)
{
int x, y;
scanf("%d%d", &x, &y);
G[x+100].push_back(y+100);
}
for(int i = 0;i<=200;i++)
{
int size = G[i].size();
if(size == 0) continue;
if(size>1)
ans+=size*(size-1)/2*(n-size);
for(int j = i+1;j<=200;j++)
{
if(G[j].size() == 0) continue;
for(int k = j+1;k<=200;k++)
{
if(G[k].size() == 0) continue;
for(int a = 0;a<G[i].size();a++)
{
for(int b = 0;b<G[j].size();b++)
{
for(int c = 0;c<G[k].size();c++)
{
if((G[k][c]-G[j][b])*(j-i) == (G[j][b]-G[i][a])*(k-j))
continue;
ans++;
}
}
}
}
}
}
printf("%I64d\n", ans);
return 0;
}