如果你能通过白书中级习题的前一题 , 那么这个题目还是很简单的 , 因为博主的数学部分没有进行专题研究 , 目前的理解还是比较基础的 , 可能对新手会有借鉴意义 , 但也不妨大神们来虐虐我啊(#^.^#)
提示:
1. 锐角三角形是比较难限制的 , 因为要求三个角都是锐角是吧
2. 但是如果我能找到一个钝角 , 那么我就一定能确定一个钝角三角形
3. 时间肯定不能n^3去搞 , 所以你需要想办法高效的枚举 , 首先难以避免的两重循环是枚举一个基准点(然后极角排序 , 这是个老套路) , 因为是找一这个点为钝角的两条边 , 所以还需要枚举一个点 , 以此来构成一条边 , 然后我们要想办法高效的找到另外有多少条边满足要求 , 对了 , 就是利用枚举的单调性
注意: 这是我看前一个题目的疑惑 , 是关于枚举顺序的 , 枚举要求不重复 , 所以顺序很重要 ,所以我们都只记录某一条边一个方向的钝角(有点抽象 , 看代码)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-10;
int dcmp(double a) { return fabs(a)<eps?0:(a<0?-1:1); }
struct points
{
double x , y;
void read(){ scanf("%lf%lf",&x,&y); }
points(double x = 0 , double y = 0):x(x),y(y){}
};
typedef points Vector;
Vector operator -(Vector a , Vector b) { return Vector(a.x-b.x , a.y-b.y); }
double angle(Vector a)
{
return atan2(a.y, a.x);
}
int n , m;
points p[1500];
double s[3000];
int main(int argc, char *argv[]) {
int Case=0;
while(cin>>n && n)
{
for(int i=0;i<n;i++) p[i].read();
long long res =0;
for(int i=0;i<n;i++)
{
m=0;
for(int j=0;j<n;j++) if(i!=j) s[m++] = angle(p[j]-p[i]);
sort(s, s+m);
for(int j=0;j<m;j++) s[j+m] = pi*2+s[j];
for(int j=0 , k=0 , l=0;j<m;j++)
{
while(dcmp(s[k+1]-s[j]-pi/2.0)<0) k++;
while(dcmp(s[l+1]-s[j]-pi)<0) l++;
res+= l-k;
}
}
long long now = (long long)n*(n-1)*(n-2)/6;
cout<<"Scenario "<<++Case<<":\nThere are "<<now-res<<" sites for making valid tracks\n";
}
return 0;
}