https://codeforces.com/problemset/problem/552/D
思路:
看了下有n^3跑过去的..看了下5s觉得n^3有点离谱了,把别人代码交上去1000ms..
正解应该是n^2logn的吧。
这个题范围最大就是100*100的矩形,所以其斜率最多200个,提前预处理出以每个点为基础的斜率上有多少点,每次遍历的时候每一点的每一个斜率上算C(X,2)个,最后用总数的C(n,3)给减去。
注意下算斜率可能卡精度(wa4
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e3+100;
typedef long long LL;
const LL inf=0x3f3f3f3f;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
map<double,double>map1[maxn];
struct P{
double x,y;
}p[maxn];
double get(LL i,LL j)
{
LL y=p[i].y-p[j].y;
LL x=p[i].x-p[j].x;
if (!x)return 100000;
LL gd=__gcd(x,y);
x/=gd;
y/=gd;
return (y*1.0/x);
}
int main(void){
cin.tie(0);std::ios::sync_with_stdio(false);
LL n;cin>>n;
LL tot=n*(n-1)*(n-2)/6;
for(LL i=1;i<=n;i++){
cin>>p[i].x>>p[i].y;
}
for(LL i=1;i<=n;i++){
for(LL j=i+1;j<=n;j++){
double k=get(i,j);
map1[i][k]++;
}
}
LL ans=0;
for(LL i=1;i<=n;i++){
for(auto j:map1[i]){
if(j.second>=2){
ans+=(j.second)*(j.second-1)/2;
}
}
}
cout<<tot-ans<<"\n";
return 0;
}