Codeforces Global Round 11 C. The Hard Work of Paparazzi
題目連結
思路:讀完題看到r的範圍就能發現一個小trick。時間相距超過2r的兩個明星必然有一種方式可以同時拍到。由於時間嚴格遞增,那麼暴力轉移dp最多隻有2r個初態,直接暴力即可。時間超過2r的可以搞一個雙指標記一下字首max即可。
注意一下dp陣列的初始值。
細節見程式碼。
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int r,n;
struct uzi{
int x,y,t;
bool operator < (const uzi & T)const{
return t<T.t;
}
}p[N];
int dp[N];
int main() {
ios::sync_with_stdio(false);
cin>>r>>n;
p[1]={1,1,0};
for(int i=1;i<=n;i++)cin>>p[i+1].t>>p[i+1].x>>p[i+1].y,dp[i+1]=-1e8;
n++;
dp[1]=0;
for(int i=2,j=0,cur=0;i<=n;i++){
while(j+1<i&&p[i].t-p[j+1].t>=2*r){
cur=max(cur,dp[j+1]);
j++;
}
if(j)dp[i]=cur+1;
for(int k=i-1;k>j;k--){
if(abs(p[k].x-p[i].x)+abs(p[k].y-p[i].y)<=p[i].t-p[k].t){
dp[i]=max(dp[i],dp[k]+1);
}
}
}
cout<<*max_element(dp+1,dp+1+n);
return 0;
}
相關文章
- Codeforces Global Round 26
- Codeforces Global Round 27
- Codeforces Global Round 13
- Codeforces Global Round 26 (A - D)
- 【CodeForces訓練記錄】Codeforces Global Round 27
- Codeforces Global Round 19 E. Best PairAI
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- C. Dominant Piranha(思維) Codeforces Round #677 (Div. 3)NaN
- Codeforces Global Round 26 補題記錄(A~C2)
- Codeforces Round #373 (Div. 1) C. Sasha and Array 線段樹
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- Educational Codeforces Round 165 (Rated for Div. 2) C. Minimizing the Sum題解
- Codeforces Round 955
- acm-(思維、奇偶性、矩陣)Codeforces Round #682 (Div. 2) C. Engineer ArtemACM矩陣
- Educational Codeforces Round 163
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 二分+前字尾預處理
- Patrick and Shopping Codeforces Round #332
- Uncowed Forces Codeforces Round #334
- Codeforces Educational Round#98 A
- Codeforces Round 962(Div .3)
- Educational Codeforces Round 172 Solution
- 2024.12.2 Educational Codeforces Round 172
- Codeforces Round #541 (Div. 2)
- Codeforces Round #469 C A. Zebras
- Codeforces Round 940 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 943 (Div. 3)
- Codeforces Round 859 (Div. 4)
- Codeforces Round 933 (Div. 3)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 1)
- Codeforces Round 948 (Div. 2)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)