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 13
- Codeforces Global Round 26
- Codeforces Global Round 27
- Codeforces Global Round 26 (A - D)
- 【CodeForces訓練記錄】Codeforces Global Round 27
- Codeforces Global Round 19 E. Best PairAI
- Codeforces Round #446 (Div. 2) C. PrideIDE
- Codeforces Round #242 (Div. 2) C. Magic FormulasORM
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Codeforces Round #215 (Div. 2) C. Sereja and AlgorithmGo
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- Codeforces Round #228 (Div. 1) C. Fox and Card GameGAM
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Arraydev
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- Codeforces Global Round 26 補題記錄(A~C2)
- Codeforces Round #407 (Div. 1) C. The Great Mixing(bfs)
- Codeforces Round #373 (Div. 1) C. Sasha and Array 線段樹
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- C. Dominant Piranha(思維) Codeforces Round #677 (Div. 3)NaN
- Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水題
- Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二進位制]
- Codeforces Round #207 (Div. 2)C. Knight Tournament(SET也可以搞定)
- Educational Codeforces Round 165 (Rated for Div. 2) C. Minimizing the Sum題解
- Codeforces Round #174
- Codeforces Round #170
- Codeforces Round 955
- acm-(思維、奇偶性、矩陣)Codeforces Round #682 (Div. 2) C. Engineer ArtemACM矩陣
- Codeforces Round #406 (Div. 1) C. Till I Collapse(可持久化線段樹)持久化
- 2024.11.17 Codeforces Round 988 (Div. 3)
- Educational Codeforces Round 32
- Codeforces Beta Round #32
- Codeforces Beta Round #23
- Codeforces Round #180
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 二分+前字尾預處理
- 2024.11.15 Codeforces Round 987(Div. 2)
- Codeforces Educational Round#98 A
- Educational Codeforces Round 1 Tutorial