链接

很巧妙的一道题,参考

把距离和速度分别作为x和y坐标,以斜率代表追赶速率,简直炫酷~

具体看上面的博客,画的很清楚,就不再抄写一遍了。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 50010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y = ):x(x),y(y){}
}p[N],ch[N];
typedef point pointt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
double mul(point p0,point p1,point p2)
{
return cross(p1-p0,p2-p0);
}
double dis(point a)
{
return sqrt(a.x*1.0*a.x+a.y*1.0*a.y);
}
bool cmp(point a,point b)
{
if(dcmp(mul(p[],a,b))==)
return dis(a-p[])<dis(b-p[]);
else
return dcmp(mul(p[],a,b))>;
}
int Graham(int n)
{
if(n<) return n;
int i,k = ,top;
point tmp;
for(i = ; i < n; i++)
{
if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
k = i;
}
if(k!=)
{
tmp = p[];
p[] = p[k];
p[k] = tmp;
}
sort(p+,p+n,cmp);
ch[] = p[];
ch[] = p[];
top = ;
for(i = ; i < n ; i++)
{
while(top>&&dcmp(mul(ch[top-],ch[top],p[i]))<=)
top--;
top++;
ch[top] = p[i];
}
return top;
}
int main()
{
int t,i,n;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i < n; i++)
scanf("%lf%lf",&p[i].y,&p[i].x);
int m = Graham(n);
int maxx = -INF,tx,maxy = -INF,ty;
if(n<)
{
cout<<"1\n";
continue;
}
for(i = ; i <= m ; i++)
{
//cout<<ch[i].x<<" "<<ch[i].y<<endl;
if(ch[i].x>maxx)
{
tx = i;
maxx = ch[i].x;
}
if(ch[i].y>maxy)
{
ty = i;
maxy = ch[i].y;
}
}
cout<<ty-tx+<<endl;
}
return ;
}
05-08 15:51