题目链接:https://ac.nowcoder.com/acm/contest/3003/D
题意就是给n个点问能够组成多少个钝角三角形
一开始写n3的暴力,好像被我写炸了,真实蠢;
后来开始了极角排序,直接统计钝角数量就行。
赛后正解居然真是暴力,想锤自己。
代码如下:
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#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 LL inf=1e18;
const int N=1e5+10;
const int maxn=1005;
const double eps=1e-12;
double x[N],y[N],temp[2*N];
LL n;
LL cal(LL x,LL y)
{
LL ans=1;
for(int i=0;i<y;i++)
ans=ans*(x-i);
for(LL i=2;i<=y;i++)
ans/=i;
return ans;
}
LL getans()
{
LL num=cal(n,3),sum=0;
for(int i=1;i<=n;i++)
{
int cnt=1;
for(int j=1;j<=n;j++)
{
if(i==j)continue;
temp[cnt]=atan2(y[j]-y[i],x[j]-x[i]);
if(temp[cnt]<0)temp[cnt]+=2*PI;
cnt++;
temp[cnt]=temp[cnt-1]+2*PI;
cnt++;
}
sort(temp+1,temp+cnt);
int l=1,r=1;
for(int j=1;j<n;j++)
{
while(temp[r]-temp[j]<PI&&r<cnt)r++;
while(temp[l]-temp[j]<=0.5*PI&&l<cnt)l++;//[l,r-1];
LL len=LL(r-l);
sum=sum+len;
}
}
return sum;
}
int main()
{
read(n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&x[i],&y[i]);
printf("%lld\n",getans());
return 0;
}
京公网安备 11010502036488号