当前位置:网站首页>Cf1427c the hard work of paparazzi
Cf1427c the hard work of paparazzi
2022-04-23 06:29:00 【cornivores】
CF1427C The Hard Work of Paparazzi
The question : There is one r*r(r≤500) The map of , The starting position is (1,1), Yes n(n≤1e5) An individual will appear at a certain point at a certain time ( Give... In ascending order of time ), Ask how many people you can meet at most .
solution : The idea of this problem is very novel , I always thought about bfs, But I can't write it out , because n It's too big . I didn't expect it to be linear at all dp . At first I heard that the solution to this problem was dp When , It feels like n ^ 2 The cycle of (dp[i] On behalf of i At a time , How many people can you meet up front ), But it will obviously time out , Here is a feature to be found , If it is n ^ 2 The kind of cycle , Will find r It's useless , In fact, it is to use r To optimize the second cycle . First , The distance between two points is at most 2r, And the time is strictly ascending , that i It must be from [0,i-2r] Turn around , The biggest must be in [i-4r,i-2r] Between ( I think the reason should be that the values here are updated from the previous values , So it can be reduced to this range ), But for the [i-2r,i-1] This part needs to be judged ( The following code also determines [i-4r,i-2r] Of ). In this case ,n ^ 2 The complexity can be optimized to n * r, It's a bit like yesterday's topic .
Thank you for pointing out ~
Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+10;
int dp[N];
struct xx {
int t, x, y;
}a[N];
int dis(xx a1, xx a2) {
return abs(a1.x-a2.x)+abs(a1.y-a2.y);
}
int main() {
memset(dp, -1, sizeof dp);
int r, n;
scanf("%d%d", &r, &n);
a[0].x = 1, a[0].y = 1; dp[0] = 0;
for(int i = 1; i <= n; ++i) scanf("%d%d%d", &a[i].t, &a[i].x, &a[i].y);
for(int i = 1; i <= n; ++i) {
for(int j = max(0, i-1-r*4); j < i; ++j) {
if(dp[j] != -1 && a[i].t - a[j].t >= dis(a[i], a[j]))
dp[i] = max(dp[i], dp[j]+1);
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) ans = max(ans, dp[i]);
printf("%d\n", ans);
return 0;
}
版权声明
本文为[cornivores]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210615591947.html
边栏推荐
- [leetcode 350] intersection of two arrays II
- Chapter 4 of line generation - linear correlation of vector systems
- [leetcode 459] duplicate substring
- Export of data
- Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
- 12. Monkeys climb mountains
- [leetcode 383] ransom letter
- [leetcode 59] spiral matrix II
- Linear algebra Chapter 1 - determinant
- Event listener
猜你喜欢
检测技术与原理
Techniques et principes de détection
Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
卡尔曼滤波与惯性组合导航
Robocode教程3——Robo机器剖析
Export of data
Best practices for MySQL storage time
Chapter 4 of line generation - linear correlation of vector systems
MySQL table constraints and table design
lambda expressions
随机推荐
Busybox initrd and initialization process
Usage scenario of copyonwritearraylist
Custom exception class
[leetcode 350] intersection of two arrays II
Algèbre linéaire chapitre 1 - déterminants
POJ - 2955 brackets interval DP
Troubleshooting of data deleted and reappeared problems
Kalman filter and inertial integrated navigation
Understanding and use of tp50, tp90 and tp99
MySQL best practices for creating tables
Practical operation - Nacos installation and configuration
Generate excel template (drop-down selection, multi-level linkage)
3. Continuous integer
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
电机与拖动(戚金清版)学习整理
Collection and map thread safety problem solving
Rust 的多线程安全引用 Arc
Sakura substring thinking
Exception handling: grab and throw model
H. Are You Safe? Convex hull naked problem