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. [ABC126F] XOR Matching

    2023-01-07 题目 题目传送门 翻译 翻译 难度&重要性(1~10):1 题目来源 AtCoder 题目算法 位运算 解题思路 因为两个相同数异或为 \(0\),所以中间放一个 \(k ...

  2. iOS视图控件的内容显示和离屏渲染流程

    iOS中UI控件内容显示流程 UIKit界面组成 iOS中组成页面的各个元素基本来自UIKit,我们可以修改布局或自定义绘制来修改UIKit元素的默认展示. UIView的页面显示内容有CALayer ...

  3. 再聊Java Stream的一些实战技能与注意点

    大家好,又见面了. 在此前我的文章中,曾分2篇详细探讨了下JAVA中Stream流的相关操作,2篇文章收获了累计 10w+阅读.2k+点赞以及 5k+收藏的记录.能够得到众多小伙伴的认可,是技术分享过 ...

  4. RocketMQ 系列(五)高可用与负载均衡

    RocketMQ 系列(五)高可用与负载均衡 RocketMQ 前面系列文章如下: RocketMQ系列(一) 基本介绍 RocketMQ 系列(二) 环境搭建 RocketMQ 系列(三) 集成 S ...

  5. iptables和firewalld

    iptables简介 iptables不是一个单一的软件工具,而是一套c/s样式的软件组,它是由工作在用户空间的iptables和工作在内核空间的vetilter模块组成,一般统称为Iptables. ...

  6. ​python爬虫——爬取天气预报信息

    在本文中,我们将学习如何使用代理IP爬取天气预报信息.我们将使用 Python 编写程序,并使用 requests 和 BeautifulSoup 库来获取和解析 HTML.此外,我们还将使用代理服务 ...

  7. hash code

    值相同却可能有不同的hashcode //对象值到底指什么?(x.equals(y) == true)应该并不代表对象值相同 class A { A(){} public boolean equals ...

  8. Cloud Bursting解决方案,Serverless容器降本增效极致体验

    本文分享自华为云社区<DTSE Tech Talk | 第42期:Cloud Bursting解决方案,Serverless容器降本增效极致体验>,作者:华为云社区精选. 线下IDC自建K ...

  9. 2022-10-22 CSP赛前隔离时的模拟赛 2:3

    T1 简单红题,不懈于写. 锐评:镜子反射出来的竟然没有镜像一下. T2 坑人东西调了 2h. 类似于 round1 的 T4. 线性 \(\Theta(n)\) 过. T3 T4 其实简单,负边权要 ...

  10. spring---面向切面(AOP @Pointcut 注解篇)

    2.1 第一个实例 接下来,我们先看一个极简的例子:所有的get请求被调用前在控制台输出一句"get请求的advice触发了". 具体实现如下: 1.创建一个AOP切面类,只要在类 ...