https://codeforc.es/contest/1463/problem/C
这是昨晚的cf题,我很难过没能ac,是因为当时的精神状态不好
这个模拟其实不难写,定义两个东西,当前位置pos和目标位置ans就好了,多睡觉吧,睡醒了才聪明啊
ans小于pos就退步,ans大于pos就进步,写了再说,先写了再说
#include<iostream> #include<cstring> #include<queue> using namespace std; typedef long long ll; const int maxn = 2e5+111; pair<ll,ll>ins[maxn],chal[maxn]; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>ins[i].first; cin>>ins[i].second; } ins[n] = make_pair(2e17,2e16); ll pos = 0,ans = 0; ans = ins[0].second; chal[0] = make_pair(0,ans); for(int i=1;i<=n;i++){ ll x = ins[i].first; ll y = ins[i].second; ll len = ins[i].first - ins[i-1].first; if(ans > pos){ pos += len; if(pos >= ans) { pos = ans; ans = y; } } else{ pos -= len; if(pos <= ans){ pos = ans; ans = y; } } chal[i] = make_pair(pos,ans); } ll ddd = 0; for(int i=0;i<n;i++){ ll y = ins[i].second; if(chal[i].first <= y && y <= chal[i+1].first){ ddd++; } else if(chal[i+1].first <= y && y <= chal[i].first){ ddd++; } } cout<<ddd<<endl<<endl; } return 0; }