标签:
题目链接:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 570 Accepted Submission(s): 183
/************************************************ ┆ ┏┓ ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃ ┃ ┆ ┆┃ ━ ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃ ┃ ┆ ┆┃ ┻ ┃ ┆ ┆┗━┓ ┏━┛ ┆ ┆ ┃ ┃ ┆ ┆ ┃ ┗━━━┓ ┆ ┆ ┃ AC代马 ┣┓┆ ┆ ┃ ┏┛┆ ┆ ┗┓┓┏━┳┓┏┛ ┆ ┆ ┃┫┫ ┃┫┫ ┆ ┆ ┗┻┛ ┗┻┛ ┆ ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar()); for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + ‘0‘); putchar(‘\n‘); } const LL mod=1e9+7; const double PI=acos(-1.0); const int inf=1e9; const int N=5e4+10; const int maxn=2e3+14; const double eps=1e-12; double temp[2*maxn]; int n; struct node { double x,y; }po[maxn]; int main() { while(scanf("%d",&n)!=EOF) { For(i,1,n) { scanf("%lf%lf",&po[i].x,&po[i].y); } LL ans1=0,ans2=0; For(i,1,n) { int cnt=0; For(j,1,n) { if(i==j)continue; temp[++cnt]=atan2(po[j].y-po[i].y,po[j].x-po[i].x); if(temp[cnt]<0)temp[cnt]+=2*PI; } sort(temp+1,temp+cnt+1); For(j,1,cnt) { temp[j+cnt]=temp[j]+2*PI; } int l=1,r=1,le=1; For(j,1,cnt) { while(temp[r]-temp[j]<PI&&r<=2*cnt)r++; while(temp[l]-temp[j]<0.5*PI&&l<=2*cnt)l++; while(temp[le]-temp[j]<=eps&&le<=2*cnt)le++; ans1=ans1+r-l; ans2=ans2+l-le; } } cout<<(ans2-2*ans1)/3<<"\n"; } return 0; }
hdu-5784 How Many Triangles(计算几何+极角排序)
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5733811.html