【题解】sweet
题目描述
为了防止糖果被小猫偷吃,John把他的糖果放在了很多的高台上,一个高台可以认为是一段平行于X轴的线段,并且高台的y坐标都是大于0的,每个高台都有左端点和高台的长度,每个高台都有糖果。所有的高台都不会重叠,也不会有公共端点。小猫一开始在地面上,他可以在地面上自由走动,然后他可以选择在地面上的任意一点跳到某个高台,然后可以吃掉该高台上的糖果,当小猫在某个高台X上时,它可以在该高台上自由的左右走动,然后它可以选择在X高台上的某点跳到高度大于或等于当前高台高度的那些高台。但小猫能跳到某高台必须满足一点:小猫的一次跳跃距离不能超过K,假设小猫从X点开始跳,如果Y高台离X点最近的距离小于等于K,那么小猫就可以跳到Y上,否则就不能跳到Y。
现在有N个高台,给出每个高台的左端点的(x,y),和该高台的长度。
给出每个高台上的糖果数量,给出K。 要你求小猫最多能吃多少糖果。(注意:高台上的糖果如果被吃了,那么下次小猫再到该高台时就没糖果吃了。)
输入格式
第一行,两个整数,N和K,表示有N个高台和小猫一次跳跃的最大距离K。1≤N≤50,1≤K≤10000;
接下来一行,有N个整数,空格分开,第i个整数表示第i个高台上拥有的糖果数量num。0≤num≤9999;
接下来一行,有N个整数,空格分开,第i个整数表示第i个高台左端点的横坐标X。1≤X≤10000;
接下来一行,有N个整数,空格分开,第i个整数表示第i个高台左端点的纵坐标Y。1≤Y≤10000。
接下来一行,有N个整数,空格分开,第i个整数表示第i个高台的长度Len。1≤Len≤1000。
输出格式
一行,输出小猫最多能吃多少糖果。
给出两点之间的距离计算公式:点(x1,y1)、(x2,y2)之间的距离:
dis=sqrt((x1-x2)×(x1-x2)+(y1-y2)×(y1-y2))
输入样例
6 2
1 2 3 4 3 5
1 1 1 4 5 5
1 3 4 1 2 3
2 1 1 2 1 1
输出样例
13
样例说明

共有6个高台,如上图所示:每个高台上面的数字表示该高台上的糖果数量。小猫开始可以跳到高台1,吃掉一个糖果,然后移动到高台1的右端点,然后跳到高台4,吃掉4个糖果,然后跳到高台5,吃掉3个糖果,最后跳到高台6,吃掉5个糖果,共吃掉13个糖果)
题解
毒瘤题,以后写思路,先看代码吧。
#include <iostream>
#include <algorithm>
#include <cmath>
#define MAXN 50 using namespace std; int n, k;
struct node
{
int num;
int x, y;
int len;
}a[MAXN];
bool cmp(node a, node b)
{
if(a.y != b.y) return a.y < b.y;
return a.x < b.x;
}
int f[MAXN];
int ans; int main()
{
cin >> n >> k;
for(register int i = ; i < n; i++) cin >> a[i].num;
for(register int i = ; i < n; i++) cin >> a[i].x;
for(register int i = ; i < n; i++) cin >> a[i].y;
for(register int i = ; i < n; i++) cin >> a[i].len;
sort(a, a + n, cmp);
for(register int i = , same = ; i < n; i++)
{
for(register int j = ; j < i; j++) if(a[i].y > a[j].y)
{
if((a[i].y - a[j].y) * (a[i].y - a[j].y) + (a[i].x - a[j].x - a[j].len) * (a[i].x - a[j].x - a[j].len) <= k * k)
{
f[i] = max(f[i], f[j]);
}
else if((a[i].y - a[j].y) * (a[i].y - a[j].y) + (a[j].x - a[i].x - a[i].len) * (a[j].x - a[i].x - a[i].len) <= k * k)
{
f[i] = max(f[i], f[j]);
}
else if((a[i].y - a[j].y) * (a[i].y - a[j].y) <= k * k
&& (a[i].x >= a[j].x && a[i].x + a[i].len <= a[j].x + a[j].len
|| a[j].x >= a[i].x && a[j].x + a[j].len <= a[i].x + a[i].len
|| a[i].x < a[j].x && a[i].x + a[i].len >= a[j].x && a[i].x + a[i].len <= a[j].x + a[j].len
|| a[j].x < a[i].x && a[j].x + a[j].len >= a[i].x && a[j].x + a[j].len <= a[i].x + a[i].len))
{
f[i] = max(f[i], f[j]);
}
}
if(!f[i])
{
if(a[i].y * a[i].y <= k * k) f[i] = a[i].num;
else continue;
}
else
{
f[i] += a[i].num;
}
if(a[i + ].y != a[i].y)
{
for(register int l = same, r = same + ; r <= i; r++)
{
if((a[r].x - a[r - ].x - a[r - ].len) * (a[r].x - a[r - ].x - a[r - ].len) > k * k)
{
for(register int j = l; j < r; j++)
{
for(register int jj = l; jj < r; jj++) if(j != jj)
{
f[j] += a[jj].num;
}
}
l = r;
}
else if(r == i)
{
for(register int j = l; j <= r; j++)
{
for(register int jj = l; jj <= r; jj++) if(j != jj)
{
f[j] += a[jj].num;
}
}
}
}
same = i + ;
}
ans = max(f[i], ans);
}
cout << ans;
return ;
}
参考程序
【题解】sweet的更多相关文章
- 洛谷 题解 P1828 【香甜的黄油 Sweet Butter】
潇洒の开始 第一步:食用头文件和定义变量, 变量干什么用的说的很清楚 #include<iostream> #include<cstdio> #include<cstri ...
- Sweet Round 1题解
感谢各位参赛者,所有的题解如下: T1 syx的奖励 这题明显是签到题了吧,随便猜猜结论就A掉了 先说怎么做吧,把所有的可走的数gcd起来,然后再与n求gcd 如果为1,则输出n,若不为1,则输出-1 ...
- 洛谷P1828 香甜的黄油 Sweet Butter
P1828 香甜的黄油 Sweet Butter 241通过 724提交 题目提供者JOHNKRAM 标签USACO 难度普及+/提高 提交 讨论 题解 最新讨论 我的SPFA为什么TLE.. 为 ...
- UVA 10497 - Sweet Child Makes Trouble 高精度DP
Children are always sweet but they can sometimes make you feel bitter. In this problem, you will see ...
- HDU 5477 A Sweet Journey 水题
A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)
[POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem 水题
A. Sweet Problem the first pile contains only red candies and there are r candies in it, the second ...
- 【香甜的黄油 Sweet Butter】
[香甜的黄油 Sweet Butter] 洛谷P1828 https://www.luogu.org/problemnew/show/P1828 JDOJ 1803 https://neooj.com ...
- 「SWTR-04」Sweet Round 04 游记
比赛链接 由于 \(\texttt{Sweet Round}\) 比赛挺好的(关键不知道为啥\(Unrated\) 开篇总结(大雾):这次比赛题目不错(有思维含量) 尽管我不会做. 我一看 \(T1\ ...
随机推荐
- python-javascript之dom
DOM DOM:(document object mode)文档对象模型.DOM为文档提供了结构化表示,并定义了如何通过脚本来访问文档结构. 目的就是为了能让js操作html元素而制定的一个规范 DO ...
- 插件化框架解读之四大组件调用原理-Activity(三)上篇
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 本文通过Activity调用原理来解读Replugin插件化技术 ...
- HDU 4366 Successor( DFS序+ 线段树 )
Successor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- Comet OJ - Contest #12
B 整个表格其实是一些联通块,取反操作不能跨连通块.所以直接统计一下每个连通块内数字不对的个数是不是偶数即可 #include<iostream> #include<cstring& ...
- 2018-8-10-win10-uwp-横向-AppBarButton
title author date CreateTime categories win10 uwp 横向 AppBarButton lindexi 2018-08-10 19:16:50 +0800 ...
- /var/lib/dpkg/lock
记性不好: Could not get lock /var/lib/dpkg/lock 锁定的文件会阻止 Linux 系统中某些文件或者数据的访问,这个概念也存在于 Windows 或者其他的操作系统 ...
- Linux帮助用法
内部命令: help COMMAND 或 man bash 外部命令: (1) COMMAND --helpCOMMAND -h(2) 使用手册(manual)man COMMAND(3) 信息页in ...
- linux上传与下载文件命令
//文件从Linux系统上传到其他系统. sz空格+文件名 //文件从其他系统下载到Linux系统. rz //之后会弹出路径选择框,选择文件,即可下载到当前路径.
- js 数组、字符串、Json互相转换
arr.join(): 数组转字符串 let arr = [1,2,3,4]; let str = arr.join(','); arr.split():字符串转数组 let str = '1,2,3 ...
- 关于python全局变量
今天踩了一个坑,记录一下,避免后犯 在constant.py 中定义了一个全局变量 ZH_LIST= [],以个用于存储配置一些信息: 在views.py 中引用了这个ZH_LIST : 然后在app ...