题目描述

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;
}

【2022牛客多校5 A题 Don‘t Starve】DP相关推荐

  1. 2022牛客多校(十)

    2022牛客多校(十) 一.比赛小结 比赛链接:"蔚来杯"2022牛客暑期多校训练营10 二.题目分析及解法(基础题) F.Shannon Switching Game? 题目链接 ...

  2. 2022牛客多校十 E-Reviewer Assignment(匈牙利算法)

    题目链接:登录-专业IT笔试面试备考平台_牛客网 题目: 样例输入: 5 3 010 010 101 011 100 样例输出: 2 2 1 3 1 题意:给定n个人和m篇文章,然后给出一个n*m的矩 ...

  3. 【2022牛客多校第六场 Z题 Game on grid】dp

    题目描述 输入描述 2 3 3 -B -B BB. 1 3 - 输出描述 no no yes no yes no 题意 有一个n*m的棋盘,Alice和Bob轮流进行操作,每操作一步都是从当前点到右边 ...

  4. (2022牛客多校五)H-Cutting Papers(签到)

    样例输入: 2022 样例输出: 3649785.912339927 题意:求|x|+|y|+|x+y|<=n所在的区域和x*x+y*y=(n/2)*(n/2)所在区域的面积并. 这道题就是一个 ...

  5. 2022牛客多校联赛第九场 题解

    比赛传送门 作者: fn 目录 签到题 A题 Car Show / 车展 基本题 B题 Two Frogs / 两只青蛙 进阶题 G题 Magic Spells / 魔法咒语 签到题 A题 Car S ...

  6. 2022牛客多校2题解报告(同步自语雀)

    一.赛后总结 总结就是缺乏清晰的大脑,当然一切的一切归因于实力不足. 开局看K,半个小时推出DP式子,交了就WA.差错没查出来,写了暴力对拍,就去看D了.后来拍了3个小时也没出问题...可能是数据生成 ...

  7. 2022牛客多校第二场CDE

    C题 题意:nim游戏,先手赢的话,尽量赢的快,输的话尽量输的慢. 求最多的游戏局数,和先手执行的最优策略数 下面给两个结论: 1,石子数异或和为0的话,先手败,否则胜 2,先手败的话,可以构造出先后 ...

  8. [manacher][hash]Magic Spells 2022牛客多校第9场 G

    题目描述 One day in the magic world, the young wizard RoundDog was learning the compatibility of spells. ...

  9. 2022牛客多校 C Grab the Seat!

    题意 二维平面,屏幕是 (0, 1)–(0, m) 的线段 有 n 行 m 列座位在屏幕前面,是坐标范围 1 ≤ x ≤ n, 1 ≤ y ≤ m 的整点 有 k 个座位已经有人,求出到屏幕的视线不被 ...

  10. [构造]Array 2022牛客多校第6场 A

    题目描述 Ranran has a sequence aaa of nnn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_na1​,a2​,⋯,an​ which s ...

最新文章

  1. R单样本t检验(ONE-SAMPLE T-TEST)
  2. python3.7[列表] 索引切片
  3. 给 TWebBrowser.Document 定义事件
  4. Python中os模块使用方法
  5. Win8.1 JAVA环境配置全过程
  6. fun(1),fun(2),fun(3)
  7. Silverlight4 ColorPicker控件
  8. sql server 中xml 数据类型的insert、update、delete
  9. 黄聪:WordPress动作钩子函数add_action()、do_action()源码解析
  10. Vue packages version mismatch:- vue@2.6.14 - vue-template-compiler@2.6.11解决方法
  11. 在JAR中打包使用JAR库
  12. 自增字段不连续_MySQL中自增主键不连续之解决方案。(20131109)
  13. 一款超强可视化报表工具:RDP报表工具
  14. 直接sql 添加字段赋值
  15. 网络间谍:你的共享文件夹网络监视器
  16. 微信小程序怎么做淘宝客优惠券商城手把手教你完成从申请到上线
  17. 鸟哥linux视频教程密码,[鸟哥linux视频教程整理]04_01_Linux用户管理命令详解
  18. 分布式计算模式:流水线
  19. 小数点后两位向上取值
  20. 网站导航栏SEO优化方法

热门文章

  1. 卸载重装Ubuntu22.04双系统
  2. UE4多人 mysql_UE4 添加多人联机功能
  3. docke 安装rap_RAP2:使用docker镜像进行构建,启动部署
  4. 华为服务器不显示u盘启动项,服务器不读u盘启动
  5. linux公社_又一个Linux发行版宣告死亡!曾经是最好的桌面版BSD操作系统
  6. 从零开始之驱动开发、linux驱动(七十一、电容触摸屏驱动)
  7. spec开发思路以及理解
  8. 聚币网API[Python2版]
  9. 脑肿瘤的影像组学:图像评估、定量特征描述和机器学习方法
  10. OLED之U8g2中文库使用