题意:
现在有n个机器人,每个机器人在距离跑道右边p的位置,以一开始速度为0,加速度为a的速度向右跑。问你有多少个机器人在某个时刻在最右边且其它机器人都在它左边。
题解:
先吐槽我队友把题目看错导致最终没A。
很简单的一道题,我们可以将位置从大到小排序,然后对于当前机器人,如果它的加速度大于等于前面的最大加速度,就进行计算,如果它追上上一个领头羊的时间小于等于上一个领头羊追上上上个领头羊的时间,就表示上个领头羊追上上上个领头羊之前就被追上了。那么pop掉。就维护一个这样的单调栈。但是要注意有可能有两个位置相同,速度相同的机器人,这样的话用map保存一个pair<起始位置,速度>。最后便利一遍栈,如果当前的pair有两个及以上,那么就不算入答案。
注意加快读
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define eps 1e-6L
#define pa pair<int,ld>
#define pi pair<int,int>
namespace Fast_IO { //orz laofu
const int MAXL((1 << 18) + 1); int iof, iotp;
char ioif[MAXL], * ioiS, * ioiT, ioof[MAXL], * iooS = ioof, * iooT = ioof + MAXL - 1, ioc, iost[55];
char Getchar() {
if (ioiS == ioiT) {
ioiS = ioif; ioiT = ioiS + fread(ioif, 1, MAXL, stdin); return (ioiS == ioiT ? EOF : *ioiS++);
}
else return (*ioiS++);
}
void Write() { fwrite(ioof, 1, iooS - ioof, stdout); iooS = ioof; }
void Putchar(char x) { *iooS++ = x; if (iooS == iooT)Write(); }
inline int read() {
int x = 0; for (iof = 1, ioc = Getchar(); ioc<'0' || ioc>'9';)iof = ioc == '-' ? -1 : 1, ioc = Getchar();
for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar())x = (x << 3) + (x << 1) + (ioc ^ 48); return x * iof;
}
inline long long read_ll() {
long long x = 0; for (iof = 1, ioc = Getchar(); ioc<'0' || ioc>'9';)iof = ioc == '-' ? -1 : 1, ioc = Getchar();
for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar())x = (x << 3) + (x << 1) + (ioc ^ 48); return x * iof;
}
template <class Int>void Print(Int x, char ch = '\0') {
if (!x)Putchar('0'); if (x < 0)Putchar('-'), x = -x; while (x)iost[++iotp] = x % 10 + '0', x /= 10;
while (iotp)Putchar(iost[iotp--]); if (ch)Putchar(ch);
}
void Getstr(char* s, int& l) {
for (ioc = Getchar(); ioc <'a' || ioc>'z';)ioc = Getchar();
for (l = 0; ioc <= 'z' && ioc >= 'a'; ioc = Getchar())s[l++] = ioc; s[l] = 0;
}
void Putstr(const char* s) { for (int i = 0, n = strlen(s); i < n; ++i)Putchar(s[i]); }
} // namespace Fast_IO
using namespace Fast_IO;
const int N=5e4+5;
struct node{
ld pos,v;
bool operator< (const node& a)const {
if(pos==a.pos)
return v>a.v;
return pos>a.pos;
}
}a[N];
pa st[N];
int top;
int dcmp(ld a,ld b){
if(-eps<=max(a,b)-min(a,b)&&max(a,b)-min(a,b)<=eps)return 0;
if(a<b)return -1;
else
return 1;
}
ld cal(ld s,ld a1,ld a2){
return s*2/(a2-a1);
}
map<pi,int>mp;
int main()
{
int t;
t=read();
while(t--){
int n;
n=read();
int pos,v;
mp.clear();
for(int i=1;i<=n;i++)
pos=read(),v=read(),a[i].pos=(ld)pos,a[i].v=(ld)v;
sort(a+1,a+1+n);
top=0;
st[0]={0,0};
int mx=a[1].v;
st[++top]={1,0};
mp[{(int)a[1].pos,(int)a[1].v}]=1;
for(int i=2;i<=n;i++){
if(dcmp(a[i].v,mx)<0)continue;
if(dcmp(a[i].v,mx)==0&&a[i].pos!=a[st[top].first].pos)continue;
while(top&&dcmp(st[top].second,cal(a[st[top].first].pos-a[i].pos,a[st[top].first].v,a[i].v))>=0)
top--;
st[top+1]={i,cal(a[st[top].first].pos-a[i].pos,a[st[top].first].v,a[i].v)};
top++;
mp[{(int)a[i].pos,(int)a[i].v}]++;
mx=a[i].v;
}
int ans=0;
for(int i=1;i<=top;i++)
if(mp[{(int)a[st[i].first].pos,(int)a[st[i].first].v}]==1)
ans++;
printf("%d\n",ans);
}
return 0;
}