当前位置:网站首页>【2022牛客多校5 A题 Don‘t Starve】DP
【2022牛客多校5 A题 Don‘t Starve】DP
2022-08-04 20:44:00 【宇智波一打七~】
题目描述
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个点,每个点都有一个食物,每个点也都有一个坐标,你可以在这些点之间走,每次的距离都必须严格小于上一次的长度,问你最多能吃到多少食物。
思路:
因为数据量是2000,所以每两个点之间的距离能在4e6的时间处理出来,然后这就是2000个点,4e6条边,时间完全ok,然后设状态dp[i]表示从(0,0)点到第i个点的能吃到食物的最多的数量,然后先把所有边按边长从大到小排序,然后从前往后dp就能保证那个距离的递减性,还有一些距离是相等的,需要在dp的时候处理出来与这个距离相同的所有边,然后把里面的值先存起来避免dp的时候把原来的值换掉以后再更新,就发生重复了,相当于环,那么看一下代码吧
#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;
}
边栏推荐
- Tear down the underlying mechanism of the five JOINs of SparkSQL
- 【数据挖掘】搜狐公司数据挖掘工程师笔试题
- Qt Designer生成的图形可以自适应窗口的大小变化
- 实现菜单拖拽排序
- vs Code runs a local web server
- Win10 uwp use ScaleTransform magnify an element
- Matlab画图2
- Oreo domain name authorization verification system v1.0.6 public open source version website source code
- web 应用开发最佳实践之一:避免大型、复杂的布局和布局抖动
- Elastic Search 根据匹配分和热度分排序
猜你喜欢
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库

微信小程序云开发 | 赠、删、改城市名称信息的应用实现

Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership

刷题-洛谷-P1304 哥德巴赫猜想
![[Data Mining] Written Exam Questions for Sohu Data Mining Engineers](/img/d9/450eeecd5c7835d40ac38da41fc08e.png)
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers

多商户商城系统功能拆解22讲-平台端分销商品

Matlab画图2

如何用好建造者模式

Web3时代的战争

腾讯云胡启明:Kubernetes云上资源的分析与优化
随机推荐
C#的Dictionary字典集合按照key键进行升序和降序排列
2、字符集-编码-解码
漫画 | 老板裁掉我两周后,又把我请回去,工资翻番!
C语言基础[通俗易懂]
无代码平台字段设置:基础设置入门教程
C#移动OA办公系统源码(基于微信企业号)
CAS :80750-24-9(脱硫生物素 NHS 酯)
顺序队列
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
C#之app.config、exe.config和vshost.exe.config作用区别
遇到MapStruct后,再也不手写PO,DTO,VO对象之间的转换了
使用 Allatori 进行 Jar 包混淆
多商户商城系统功能拆解22讲-平台端分销商品
SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值试读版
Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO
五分钟入门文本处理三剑客grep awk sed
KubeSphere简介,功能介绍,优势,架构说明及应用场景
Retrofit的使用及原理详解
Five Minutes Introductory Text Processing Three Musketeers grep awk sed
【AGC】构建服务1-云函数示例