当前位置:网站首页>[2022 Nioke Duo School 5 A Question Don't Starve] DP
[2022 Nioke Duo School 5 A Question Don't Starve] DP
2022-08-04 20:57:00 【Uchiha one hit seven~】
题目描述
NIO purchased a new game, Don’t Starve, a sandbox game published by Klei Entertainment Inc. This game revolves around a scientist named Wilson who finds himself in a dark and gloomy world and must survive for as long as possible.
In the very beginning, NIO should help Wilson to gather some food for survival. Assume that when controlling Wilson to walk towards a location on the map, NIO should keep pressing the left button on the mouse, and when Wilson comes to the place where there is food, NIO should stop pressing the mouse, but press the space key on the keyboard to collect the food at this location. As NIO will feel tired of pressing the mouse for a long time and his finger will become very uncomfortable after a long time of pressing, the time he is willing to press the mouse after each collection is strictly decreased. Suppose there are NN locations on the 2-D plane, and at each point, there is only one unit of food. And NIO will start at the original point on the plane. You can assume that each point has an infinite number of food items, but only one can be taken at a time.
What is the maximum amount of food can NIO get for Wilson? Note that the food will be refreshed after Wilson left.
输入输出描述
样例输入
7
-7 21
70 64
45 -52
68 -93
-84 -16
-83 64
76 99
样例输出
4
题意:
给你n个点,Each point has a food,Each point also has a coordinate,You can walk between these points,The distance each time must be strictly less than the length of the previous time,Ask how much food you can eat.
思路:
因为数据量是2000,So the distance between every two points can be 4e6的时间处理出来,然后这就是2000个点,4e6条边,complete timeok,Then set the statusdp[i]表示从(0,0)点到第iThe maximum amount of food one can eat,Then first sort all the sides by length from largest to smallest,然后从前往后dpThat distance can be guaranteed to decrease,There are also some distances that are equal,需要在dpWhen processing out all edges with the same distance,Then save the value inside to avoid itdpWhen the original value is replaced, it will be updated later,Repeated,equivalent to a ring,Then take a look at the code
#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
#define int long long
#define x first
#define y second
struct node{
int x,y,w,id;
bool operator<(const node&t)const{
return w > t.w;
}
}e[N*N];
typedef pair<int,int> PII;
int dis(PII a,PII b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
PII loc[N];
int f[N*N];
signed main(){
int n,tt=0;
while(scanf("%lld",&n)!=EOF){
tt = 0;
for(int i=1;i<=n;i++){
scanf("%lld%lld",&loc[i].x,&loc[i].y);
e[++tt] = {
i,1,dis(loc[0],loc[i]),1};
f[i] = -1e9;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i != j) e[++tt] = {
i,j,dis(loc[i],loc[j]),0};
sort(e+1,e+1+tt);
for(int i=1;i<=tt;){
int j = i;
queue<PII> q;
while(j<=tt&&e[i].w == e[j].w) j++;
for(int k=i;k<j;k++) if(e[k].id) q.push({
e[k].x,1});
else q.push({
e[k].x,f[e[k].y]+1});
while(q.size()) f[q.front().x] = max(f[q.front().x],q.front().y),q.pop();
i=j;
}
int ans = 0;
for(int i=1;i<=n;i++) ans = max(ans,f[i]);
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- 如何用好建造者模式
- 88.(cesium之家)cesium聚合图
- C语言——青蛙跳台阶(递归)
- vim clear last search highlighting
- KubeSphere简介,功能介绍,优势,架构说明及应用场景
- Oreo domain name authorization verification system v1.0.6 public open source version website source code
- 机器学习_02
- 三种方式设置特定设备UWP XAML view
- Getting Started with Lattice Passwords
- 某男子因用本地虚拟机做压测,惨遭字节面试官当场嘲笑
猜你喜欢
腾讯云胡启明:Kubernetes云上资源的分析与优化
【TypeScript】深入学习TypeScript枚举
【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格
C语言——青蛙跳台阶(递归)
PowerCLi 批量配置NTP
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
[Teach you to use the serial port idle interrupt of the STM32HAL library]
88. (the home of cesium) cesium polymerization figure
ts集成和使用
【手把手教你使用STM32HAL库的串口空闲中断】
随机推荐
ADB 安装 + 打驱动全教程
adb控制常用命令
Apache服务器的配置[通俗易懂]
Win10 uwp use ScaleTransform magnify an element
推荐系统_刘老师
Nuxt.js的优缺点和注意事项
常用正则表达式[通俗易懂]
vs Code 运行一个本地WEB服务器
mdk5.14 cannot be burned
Configure laravel queue method using fort app manager
composition-api
[AGC] Build Service 1 - Cloud Function Example
for 循环中的 ++i 与 i++
run command for node
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
[21天学习挑战赛——内核笔记](二)——设备树基础
dotnet 删除只读文件
DICOM医学影像协议
[TypeScript] In-depth study of TypeScript enumeration
【TypeScript】深入学习TypeScript枚举