当前位置:网站首页>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
边栏推荐
- PHP processing JSON_ Decode() parses JSON stringify
- [leetcode 54] spiral matrix
- 4. Print form
- Troubleshooting of data deleted and reappeared problems
- [leetcode 67] sum of two binary numbers
- Best practices for MySQL storage time
- Practical operation - Nacos installation and configuration
- Create binary tree
- Example of ticket selling with reentrant lock
- 20 excellent plug-ins recommended by idea
猜你喜欢
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Implementation of displaying database pictures to browser tables based on thymeleaf
[leetcode 59] spiral matrix II
Explain of MySQL optimization
Kibana search syntax
[leetcode 54] spiral matrix
Guaba and Computational Geometry
Create binary tree
[leetcode 401] binary Watch
[leetcode 19] delete the penultimate node of the linked list
随机推荐
卡尔曼滤波与惯性组合导航
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
Failure to deliver XID in Seata distributed transaction project
-- SQL query and return limit rows
Integration and induction of knowledge points of automatic control principle (Han min version)
H. Are You Safe? Convex hull naked problem
GNU EFI header file
[leetcode 228] summary interval
2. Average length of words
Implementation of displaying database pictures to browser tables based on thymeleaf
程序設計訓練
The problem that the page will refresh automatically after clicking the submit button on the form is solved
7.Domino piling
MySQL occasional Caton
12. Monkeys climb mountains
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
A sharp tool to improve work efficiency
C language file operation
Generate excel template (drop-down selection, multi-level linkage)
Preparedstatement prevents SQL injection