1. 程式人生 > >Codeforces Round #558 (Div. 2)C(計算幾何,排列組合,模擬)

Codeforces Round #558 (Div. 2)C(計算幾何,排列組合,模擬)

urn 計算 ont out turn long long using truct c++

#include<bits/stdc++.h>
using namespace std;
typedef struct{
double k,b;
}node;
node k[1000007];
bool cmp(node&a,node&b){
if(a.k==b.k)
return a.b<b.b;
return a.k<b.k;
}
long long x[1007],y[1007];
int main(){
long long n,ans=0,tot=0;
scanf("%lld",&n);
for(long long i=1;i<=n;++i)
scanf("%lld%lld",&x[i],&y[i]);


for(long long i=1;i<=n;++i){
for(long long j=1;j<i;++j){
if(x[i]!=x[j])
k[++tot].k=(y[i]-y[j])*1.0/(x[i]-x[j]),k[tot].b=y[i]-x[i]*k[tot].k;
else
k[++tot].b=x[i],k[tot].k=1000000;
}
}
sort(k+1,k+1+tot,cmp);
long long i=1;
for(long long i=tot;i>=1;--i)
if(k[i].k==k[i-1].k&&k[i].b==k[i-1].b)

k[i].k=10000000;
sort(k+1,k+1+tot,cmp);
for(long long i=1;i<=tot;++i)
if(k[i].k==10000000){
tot=i-1;
break;
}
while(i<=tot){
long long x=i;
while(k[i].k==k[i+1].k)
i++;
ans+=(i-x+1)*(x-1);
i++;
}
cout<<ans;
return 0;
}

Codeforces Round #558 (Div. 2)C(計算幾何,排列組合,模擬)