标签:
这道题容易出问题的地方一点就是由于有一步整体乘2导致数组开小了,另一点是关于三点共线,这个问题想了很久结果发现其实容斥中已经自动排除掉这种情况了。另外顺便提一下,atan(x) -> [-pi/2,pi/2)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; #define MAXN 200010 #define inf 1e1000 #define PI 3.1415926535897832 const double pi=PI; double h[MAXN]; int main() { freopen("input.txt","r",stdin); int i,j,k; int n,x,y; scanf("%d",&n); for (i=0;i<n;i++) { scanf("%d%d",&x,&y); double a; if (x)a=(double)y/x; else if (x>0)a=(double)inf; else a=-inf; h[i]=atan(a); if (x<0 || (x==0 && y>0))h[i]+=PI; h[i+n]=h[i]+PI*2; } long long ans=(long long)n*(n-1)*(n-2)/6; n*=2; sort(h,h+n); for (i=0;i*2<n;i++) { x=upper_bound(h+i,h+n,h[i]+PI)-h-i;; x--; ans-=(long long)x*(x-1)/2; } printf("%lld\n",ans); return 0; }
bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥
标签:
原文地址:http://www.cnblogs.com/mhy12345/p/4201262.html