读了一遍,还在想简单嘛,写完代码一试样例,自己理解错误,还是一句话的理解不到位,后面又读了好几遍,忽才发现自己的问题。。。。。教育场100C..
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
ll t[N];
ll x[N];
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
int res=0;
for(int i=1;i<=n;i++)
{
cin>>t[i]>>x[i];
}
t[0]=0;
t[n+1]=(int)2e9+5;
int l=1;
int p=0;
while(l<=n)
{
int tt=t[l]+abs(x[l]-p);
if(tt>=t[l]&&tt<=t[l+1])res++;
int t1=l;
int tp=p;
p=x[l];
for(int j=l+1;j<=n+1;j++)
{
if(t[j]>=tt)
{
l=j;
break;
}
else
{
int pt=t[l]+abs(x[j]-tp);
if(pt>=t[j]&&pt<=t[j+1]&&((x[j]>=tp&&x[j]<=x[t1])||(x[j]<=tp&&x[j]>=x[t1])))
{
res++;
//cout<<pt<<' '<<j<<" 666"<<endl;
}
}
}
}
cout<<res<<endl;
}
return 0;
}



京公网安备 11010502036488号