[SCOI2007]组队 差分
题解:
一开始固定H然后找性质找了很久也没有找到任何有用的东西。。。。。。
然后大佬告诉我一个神奇的方法。。。
首先我们化一波式子:
设$H$表示高度的最小值,$V$表示速度的最小值
$$A(h[i] - H) - B(v[i] - V) \le C$$
$$Ah[i] - AH + Bv[i] - BV \le C$$
如果我们枚举$h[i]$,那么$h[i]$就可以被当做一个常量,于是我们把常量都放在一起。
设$$S_{i} = Ah[i] - AH - C$$
则$$S_{i} + BV[i] - BV \le 0$$
$$S_{i} + BV[i] <= BV$$
$$\frac{S_{i}}{B} + V[i] \le V \le V[i]$$
最后那个$\le V[i]$是因为V是最小值.
于是我们可以发现,在固定H的情况下,对于任意一个V[i],它可以对在$[\frac{S_{i}}{B} + V[i], V[i]]$之间的V产生贡献。
于是对于每个固定的H,我们的最大答案就看V最大能被多少个点产生贡献。
差分维护即可
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 5500
#define ac 101000
#define LL long long int n, ans, maxn, d[ac];
int A, B, C; struct node{
int h, v;
friend bool operator < (const node &a, const node &b){return a.h < b.h;}
}s[AC]; inline int read()
{
int x = ;char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x;
} inline void upmax(int &a, int b){
if(b > a) a = b;
} inline void pre()
{
n = read(), A = read(), B = read(), C = read();
for(R i = ; i <= n; i ++)
{
s[i].h = read(), s[i].v = read();
upmax(maxn, s[i].v);
}
sort(s + , s + n + );
} void work()
{
for(R i = ; i <= n; i ++)//枚举minh
{
int H = s[i].h, all = H * A;
for(R j = i; j <= n; j ++)//在h符合条件的点当中选点来更新minv
{
int l = (s[j].h * A - all - C) / B + s[j].v, r = s[j].v;
if(l <= ) l = ;
if(l > r) continue;
++ d[l], -- d[r + ];
}
int tmp = ;
for(R j = ; j <= maxn; j ++)
tmp += d[j], upmax(ans, tmp), d[j] = ;
}
printf("%d\n", ans);
} int main()
{
freopen("in.in", "r", stdin);
pre();
work();
fclose(stdin);
return ;
}
不知道为什么卡不过大佬QAQ。。。
[SCOI2007]组队 差分的更多相关文章
- BZOJ 1071 [SCOI2007]组队
1071: [SCOI2007]组队 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1330 Solved: 417[Submit][Status][ ...
- bzoj1071[SCOI2007]组队
1071: [SCOI2007]组队 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2472 Solved: 792[Submit][Status][ ...
- 【BZOJ1071】[SCOI2007]组队(神仙题)
[BZOJ1071][SCOI2007]组队(神仙题) 题面 BZOJ 洛谷 题解 首先把式子整理一下,也就是\(A*h+B*v\le C+A*minH+B*minV\) 我们正常能够想到的做法是钦定 ...
- 1071: [SCOI2007]组队
1071: [SCOI2007]组队 https://lydsy.com/JudgeOnline/problem.php?id=1071 分析: dp+单调性. A*(hi–minH)+B*(si–m ...
- 【题解】SCOI2007组队
恩……为什么大家都这么执着于 \(O(n^{2})\) 的复杂度捏?如果接受 \(O(n^{2} + nV)\) 的复杂度,那这题可不是道**题吗( • ̀ω•́ )✧ 首先把所有的人按照身高排个序, ...
- 1071: [SCOI2007]组队 - BZOJ
Description NBA每年都有球员选秀环节.通常用速度和身高两项数据来衡量一个篮球运动员的基本素质.假如一支球队里速度最慢的球员速度为minV,身高最矮的球员高度为minH,那么这支球队的所有 ...
- BZOJ.1071.[SCOI2007]组队(思路)
题目链接 三个限制: \(Ah-AminH+Bv-BminV\leq C\ \to\ Ah+Bv\leq C+AminH+BminV\) \(v\geq minV\) \(h\geq minH\) 记 ...
- BZOJ1071: [SCOI2007]组队【双指针】【思维好题】
Description NBA每年都有球员选秀环节.通常用速度和身高两项数据来衡量一个篮球运动员的基本素质.假如一支球队里速度最慢的球员速度为minV,身高最矮的球员高度为minH,那么这支球队的所有 ...
- [SCOI2007]组队
嘟嘟嘟 这题有人说部分分O(n3)暴力,然而我暴力都没写过,调了半天也没用……还是看题解吧 首先,咱把A * ( h – minH ) + B * ( s – minS ) <= C 变个型,得 ...
随机推荐
- CakePHP中回调函数的使用
我们知道模型主要是用来处理数据的,有时我们想在模型操作之前或之后做一些额外逻辑处理,这时候就可以使用回调函数. 回调函数有很多种,beforeFind,afterFind,beforeValidate ...
- Use GitHub Desktop to get GitHub projects
Find the project's https git file in the home page of the project. e.g. https://github.com/PrismLibr ...
- lesson 24 A skeleton in the cupboard
lesson 24 A skeleton in the cupboard conceal sth from sb 对某人隐藏某事 He conceals his girlfriend from his ...
- TPO-12 C2 A problem of the TA's payroll
TPO-12 C2 A problem of the TA's payroll payroll n. 工资单:在册职工人数:工资名单: paycheck n. 付薪水的支票,薪水 paperwork ...
- leetcode-二叉树的层次遍历(Java)
给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层 ...
- 参数为json格式的接口
1.参数为json格式,需要添加一个header信息web_add_header("Content-type", "application/json"); 2. ...
- python 文件编译成exe可执行文件。
pyinstaller打包方法: pyinstaller安装参考地址:http://www.pyinstaller.org/ pywin32的下载地址:https://sourceforge.net/ ...
- Matlab 图象操作函数讲解
h = imrect;pos = getPosition(h); 这个函数用来获取图象上特定区域的坐标,其中pos的返回值中有四个参数[xmin,ymin,width,height],特定区域的左上角 ...
- LeetCode 100——相同的树
1. 题目 2. 解答 针对两棵树的根节点,有下列四种情况: p 和 q 都为空,两棵树相同: p 不为空 q 为空,两棵树不相同: p 为空 q 不为空,两棵树不相同: p 和 q 都不为空,如果两 ...
- Python3 小工具-ARP扫描
from scapy.all import * import optparse import threading import os def scan(ipt): pkt=Ether(dst='ff: ...