BZOJ不允许除以0。
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #define maxv 250 #define inf 0x7f7f7f7f using namespace std; struct pnt { double x,y; }p[maxv]; int n,cnt=0; double stack[200500]; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) { if (p[i].x!=p[j].x) stack[++cnt]=(p[j].y-p[i].y)/(p[j].x-p[i].x); else stack[++cnt]=inf; } sort(stack+1,stack+cnt+1); int ret=1; for (int i=2;i<=cnt;i++) if (fabs(stack[i]-stack[i-1])>1e-8) ret++; printf("%d ",ret); return 0; }