枚举直线,计算斜率,排序,统计答案。
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define EPS 0.00000001 #define INF 99999999999999999999.0 #define N 201 typedef double db; int n,m,sta,ans; db xs[N],ys[N],line[N*N]; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%lf%lf",&xs[i],&ys[i]); for(int i=1;i<=n;++i) for(int j=i+1;j<=n;++j) line[++m]=(fabs(xs[i]-xs[j])<EPS?INF:(ys[i]-ys[j])/(xs[i]-xs[j])); sort(line+1,line+m+1); for(int i=1;i<=m;++i) if(i==1||fabs(line[i]-line[i-1])>EPS) ++ans; printf("%d\n",ans); return 0; }
时间: 2024-11-05 16:58:30