题面:
题意:
在一个水平数轴上有n个点,给定每个点的坐标和加速度,每个点的初始速度均为0,这些点同时开始向右运动,可向右延伸至无穷远。问有多少个点在某一时刻成为过最右边的点,若最右边的点是两点并列,那么他们都不算最右边的点。
题解:
我们写出每个点的 位移–时间 表达式,其中位移(x 轴)为纵轴,时间( t 轴)为横轴。
其中 x=x0+21at2
我们发现,做出 n 个这样的图像(只保留 t 的非负半轴上的图像),最终从 x轴正无穷方向往下看能看到线就是那些成为过最右边的点的曲线。
为了方便,我们将 时间–位移 坐标系转换为 时间–位移2坐标系。这样我们只需处理 n 条直线在 t2轴的非负半轴上面的情况即可。
我们先按照直线的斜率从小到大排序,斜率相同按照b从大到小排序。
现在先考虑按照斜率排好的第 i 条直线和第 i+1 条直线,如果他们的交点在 t2轴的非正半轴,那么第 i 条直线一定不可见。
现在考虑按照斜率排好序的三条直线 i - 1 ,i ,i +1
若 i 与 i + 1 的交点在 i 与 i - 1 交点的左侧,那么 i 不可见。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#define ui unsigned int
#define ll long long
#define llu unsigned ll
#define ld long double
#define pr make_pair
#define pb push_back
#define lc (cnt<<1)
#define rc (cnt<<1|1)
#define len(x) (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=1e9+9;
const double eps=1e-8;
const double pi=acos(-1.0);
const int hp=13331;
const int maxn=100100;
const int maxm=100100;
const int up=100000;
const ll inv2=500000005;
const ll sqrt5=383008016;
int sgn(double x)
{
if(abs(x)<eps) return 0;
if(x<0) return -1;
return 1;
}
//y=ax+b
struct node
{
ll a,b;
bool operator <(const node &p) const
{
if(a!=p.a) return a<p.a;
return b>p.b;
}
}a[maxn];
int st[maxn],top=0;
map<pair<ll,ll>,int>mp;
double dx(int i,int j)
{
return (a[j].b-a[i].b)*1.0/(1.0*(a[i].a-a[j].a));
}
int main(void)
{
int tt;
scanf("%d",&tt);
while(tt--)
{
mp.clear();
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a[i].b,&a[i].a);
//斜率和截距同乘以2,相对关系不变
a[i].b*=2;
mp[pr(a[i].a,a[i].b)]++;
}
sort(a+1,a+n+1);
top=0;
for(int i=1;i<=n;i++)
{
if(i>1&&a[i].a==a[i-1].a) continue;
while(top>=1&&sgn(dx(st[top],i))<=0) top--;
while(top>1&&sgn(dx(st[top],i)-dx(st[top],st[top-1]))<=0) top--;
st[++top]=i;
}
int ans=0;
for(int i=1;i<=top;i++)
{
if(mp[pr(a[st[i]].a,a[st[i]].b)]<=1)
ans++;
}
printf("%d\n",ans);
}
return 0;
}