Problem Statement

On a number line, there are $N$ fish swimming.

Fish $i$, which has a weight of $W_i$, is at the coordinate $X_i$ at time $0$ and moves at a speed of $V_i$ in the positive direction.

Takahashi will choose an arbitrary real number $t$ greater than or equal to $0$ and do the following action at time $t$ just once.

Action: Choose an arbitrary real number $x$. Catch all fish whose coordinates are between $x$ and $x+A$, inclusive.

Find the maximum total weight of fish that he can catch.

Constraints

  • $1 \leq N \leq 2000$
  • $1 \leq A \leq 10^4$
  • $1 \leq W_i\leq 10^4$
  • $0 \leq X_i\leq 10^4$
  • $1 \leq V_i\leq 10^4$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$ $A$
$W_1$ $X_1$ $V_1$
$W_2$ $X_2$ $V_2$
$\vdots$
$W_N$ $X_N$ $V_N$

Output

Print the answer.


Sample Input 1

3 10
100 0 100
1 10 30
10 20 10

Sample Output 1

111

At time $0.25$, fish $1$, $2$, and $3$ are at the coordinates $25$, $17.5$, and $22.5$, respectively. Thus, the action done at this time with $x=16$ catches all the fish.


Sample Input 2

3 10
100 100 100
1 10 30
10 20 10

Sample Output 2

100

One optimal choice is to do the action at time $0$ with $x=100$.


Sample Input 3

4 10
1000 100 10
100 99 1
10 0 100
1 1 1

枚举我们选择的第一条鱼。那么如果现在的时间是 \(t\),如果 \(t\) 秒时一条鱼在这条鱼的右边 \(a\) 格以内,那么这条鱼就能被选中。

称这条鱼的右边 \(a\) 格为答案区间,我们可以算出剩下每条鱼进入答案区间的时间和出来的时间,从而算出每条鱼被算入答案的时间区间。其实就是根据速度大小和差了多远去判断。当然,如果一直不在,就不理这条鱼。如果一直都在,就把这个区间设为 \([1,10000]\)。然后现在要选定一个时间,让他被覆盖的次数最多。那么把所有时间离散化,差分就可以了。

#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,x[N],w[N],v[N],c[N<<1],m,ans;
double lsh[N<<1];
struct node{
double l,r;
int w;
}xd[N];
int abss(int x)
{
return x<0? -x:x;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d%d",w+i,x+i,v+i);
for(int i=1;i<=n;i++)
{
int k=0,idx=0;
memset(c,0,sizeof(c));
for(int j=1;j<=n;j++)
{
if(v[i]==v[j])
{
if(x[j]>=x[i]&&x[j]-x[i]<=m)
{
xd[++k].l=0,xd[k].r=100000;
lsh[++idx]=0,lsh[++idx]=100000;
xd[k].w=w[j];
}
}
if(v[i]<v[j]){
if(x[j]-x[i]>m)
continue;
if(x[j]>=x[i])
xd[++k].l=0;
else
xd[++k].l=1.00*(x[i]-x[j])/(v[j]-v[i]);
xd[k].r=1.00*(x[i]+m-x[j])/(v[j]-v[i]);
xd[k].w=w[j];
lsh[++idx]=xd[k].l;
lsh[++idx]=xd[k].r;
}
if(v[i]>v[j])
{
if(x[j]<x[i])
continue;
if(x[i]+m>x[j])
xd[++k].l=0;
else
xd[++k].l=1.00*(x[j]-x[i]-m)/(v[i]-v[j]);
xd[k].r=1.00*(x[j]-x[i])/(v[i]-v[j]);
xd[k].w=w[j];
lsh[++idx]=xd[k].l;
lsh[++idx]=xd[k].r;
}
}
// printf("%d\n",k);
sort(lsh+1,lsh+idx+1);
for(int j=1;j<=k;j++)
{
int l=lower_bound(lsh+1,lsh+idx+1,xd[j].l)-lsh;
int r=lower_bound(lsh+1,lsh+idx+1,xd[j].r)-lsh;
c[l]+=xd[j].w,c[r+1]-=xd[j].w;
// printf("%d %d\n",l,r);
}
// putchar('\n');
for(int j=1;j<=idx;j++)
c[j]+=c[j-1],ans=max(ans,c[j]);
}
printf("%d",ans);
}

[ABC274F] Fishing的更多相关文章

  1. ZOJ 1015 Fishing Net(弦图判定)

    In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tool ...

  2. bzoj 1242: Zju1015 Fishing Net 弦图判定

    1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 214  Solved: 81[Submit ...

  3. Poj/OpenJudge 1042 Gone Fishing

    1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...

  4. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  5. uva757 - Gone Fishing(馋)

    题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...

  6. ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net

    ●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...

  7. Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent

    Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱 ...

  8. CSU 1859 Gone Fishing(贪心)

    Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...

  9. Gone Fishing(贪心)

    Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...

  10. LightOJ1106 Gone Fishing

    Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...

随机推荐

  1. 《Kali渗透基础》02. 基本工具

    @ 目录 1:基本工具 1.1:NetCat 1.1.1:命令参数 1.1.2:示例 1.2:NCat 1.2.1:命令参数 1.2.2:示例 1.3:WireShark 1.4:TCPdump 1. ...

  2. 《数据结构-C语言》单链表

    @ 目录 单链表 结构定义 初始化 建立 清空 求表长 判断是否为空表 取值 查找 插入 删除 销毁 遍历打印 测试 单链表 结构定义 #include <stdio.h> #includ ...

  3. 2023-08-30:用go语言编写。两个魔法卷轴问题。 给定一个数组arr,其中可能有正、负、0, 一个魔法卷轴可以把arr中连续的一段全变成0,你希望数组整体的累加和尽可能大。 你有两个魔法卷轴,

    2023-08-30:用go语言编写.两个魔法卷轴问题. 给定一个数组arr,其中可能有正.负.0, 一个魔法卷轴可以把arr中连续的一段全变成0,你希望数组整体的累加和尽可能大. 你有两个魔法卷轴, ...

  4. 聊透 GPU 通信技术——GPU Direct、NVLink、RDMA 审核中

    最近人工智能大火,AI 应用所涉及的技术能力包括语音.图像.视频.NLP 等多方面,而这些都需要强大的计算资源支持.AI 技术对算力的需求是非常庞大的,虽然 GPU 的计算能力在持续提升,但是对于 A ...

  5. linux日常运维(三) GRUB 2的维护

    GRUB 2简介 GRUB GRUB是linux系统默认的引导加载程序.linux加载一个系统前,它必须有一个引导加载程序中特定指令(比如MBR记录)去引导系统.这个程序一般是位于系统的主硬盘驱动器或 ...

  6. os --- 多种操作系统接口¶

    os.path --- 常用路径操作 源代码: Lib/posixpath.py (用于 POSIX) 和 Lib/ntpath.py (用于 Windows). 此模块实现了一些有用的路径名称相关函 ...

  7. SVN: Could not resolve hostname 解决方法_

    svn 报错如下 org.tigris.subversion.javahl.ClientException: RA layer request failed svn: OPTIONS of '[你的s ...

  8. ESP32-MicroPython without Thonny

    why witout Thonny? 最近闲来在ESP32上用MicroPython捣鼓些小玩具,见很多教程推荐使用Thonny.欣然往之,竟是个这,实在不能认同.Thonny esp32-Micro ...

  9. 记一次 .NET某新能源检测系统 崩溃分析

    一:背景 1. 讲故事 前几天有位朋友微信上找到我,说他的程序会偶发性崩溃,一直找不到原因,让我帮忙看一下怎么回事,对于这种崩溃类的程序,最好的办法就是丢dump过来看一下便知,话不多说,上windb ...

  10. 关于Halcon中variation_model模型的快速解读。

    十一期间在家用期间研读了下Halcon的variation_model模型,基本上全系复现了他的所有技术要求和细节,这里做个记录. 其实这个模型的所有原理都不是很复杂的,而且Halcon中的帮助文档也 ...