[hdu7026]Might and Magic
(以下默认$A_{0},D_{0},P_{0},K_{0}$都为非负整数)
显然存活轮数$S=\lceil\frac{H_{0}}{C_{p}\max(A_{1}-D_{0},1)}\rceil$是一个关键的变量,且根据数论分块其仅有$o(\sqrt{H_{0}})$种取值,不妨利用数论分块直接$o(\sqrt{H_{0}})$枚举,进而也可以确定$D_{0}$(取对应的最小值即可)
(上取整的数论分块实际上即将$H_{0}-1$即可)
进一步的,有以下结论:存在一种取到最值的方案,满足$A_{0}=0$或$A_{0}=N'$
关于证明,考虑再枚举这$S$轮中物理攻击和魔法攻击的轮数,即$S_{p}$和$S_{m}$(其中$S_{p}+S_{m}=S$)
接下来,考虑如何分配物理攻击和魔法攻击的点数,令$F_{p}(x)$和$F_{m}(x)$分别为给物理攻击和魔法攻击分配$x$点的最大伤害值,显然有
$$
\begin{cases}F_{p}(x)=C_{p}S_{p}\max(x-D_{1},1)\\F_{m}(x)=C_{m}\begin{cases}\lfloor\frac{x}{2}\rfloor(x-\lfloor\frac{x}{2}\rfloor)&(\lfloor\frac{x}{2}\rfloor\le S_{m})\\S_{m}(x-S_{m})&(\lfloor\frac{x}{2}\rfloor>S_{m})\end{cases}\end{cases}
$$
最终答案即求$F(x)=F_{p}(x)+F_{m}(N'-x)$在$x\in [0,N']$的最大值,不难证明$F_{p}$和$F_{m}$都是下凸的,进而将$F_{m}$翻转后和$F_{p}$求和仍是下凸的,也即$F$是下凸的
同时,下凸函数的最大值显然在端点处取到,即$x=0$或$x=N'$,显然$x$也即$A_{0}$,结论得证
通过这个结论,对两类分别讨论:
1.若$A_{0}=0$,考虑再枚举$K_{0}$,答案即
$$
\begin{cases}C_{p}(S-K_{0})+C_{m}K_{0}(N'-K_{0})&(K_{0}<S)\\C_{m}S(N'-K_{0})&( K_{0}\ge S)\end{cases}
$$
(为了保证魔法攻击不劣于物理攻击,可以令$K_{0}<N'$,但实际上也会在下面的情况中考虑)
即是一个关于$K_{0}$的分段一次和二次函数, 不难求极值
2.若$A_{0}=N'$,显然全部使用物理攻击,答案即$C_{p}S\max(A_{0}-D_{1},1)$
由于有$t$组数据,最终总复杂度为$o(t\sqrt{H_{0}})$,可以通过


- 1 #include<bits/stdc++.h>
- 2 using namespace std;
- 3 #define ll long long
- 4 int t,Cp,Cm,H0,A1,D1,n;
- 5 ll ans;
- 6 ll f(ll a,ll b,ll c,int x){
- 7 return a*x*x+b*x+c;
- 8 }
- 9 ll get_max(ll a,ll b,ll c,int l,int r){
- 10 ll pos=-b/(a<<1),ans=max(f(a,b,c,l),f(a,b,c,r));
- 11 if ((l<=pos)&&(pos<=r))ans=max(ans,f(a,b,c,pos));
- 12 if ((l<=pos+1)&&(pos+1<=r))ans=max(ans,f(a,b,c,pos+1));
- 13 return ans;
- 14 }
- 15 int main(){
- 16 scanf("%d",&t);
- 17 while (t--){
- 18 scanf("%d%d%d%d%d%d",&Cp,&Cm,&H0,&A1,&D1,&n);
- 19 ans=0;
- 20 for(int i=1,j;i<=A1;i=j+1){
- 21 if (i>=H0)j=A1;
- 22 else j=min((H0-1)/((H0-1)/i),A1);
- 23 int S=((H0+i-1)/i+Cp-1)/Cp,D0=A1-j,nn=n-D0;
- 24 if (nn<0)continue;
- 25 if (min(nn,S)>1)ans=max(ans,get_max(-Cm,(ll)Cm*nn-Cp,(ll)Cp*S,1,min(nn,S)-1));
- 26 if (S<nn)ans=max(ans,(ll)Cm*S*(nn-S));
- 27 ans=max(ans,(ll)Cp*S*max(nn-D1,1));
- 28 }
- 29 printf("%lld\n",ans);
- 30 }
- 31 return 0;
- 32 }
[hdu7026]Might and Magic的更多相关文章
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- [8.3] Magic Index
A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted ar ...
- Python魔术方法-Magic Method
介绍 在Python中,所有以"__"双下划线包起来的方法,都统称为"Magic Method",例如类的初始化方法 __init__ ,Python中所有的魔 ...
- 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律
F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- 一个快速double转int的方法(利用magic number)
代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
- Magic xpa 2.5发布 Magic xpa 2.5 Release Notes
Magic xpa 2.5發佈 Magic xpa 2.5 Release Notes Magic xpa 2.5 Release NotesNew Features, Feature Enhance ...
- How Spring Boot Autoconfiguration Magic Works--转
原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...
随机推荐
- 7.JVM调优-方法区,堆,栈调优详解
通常我们都知道在堆空间新生代Eden区满了,会触发minor GC, 在老年代满了会触发full GC, 触发full GC会导致Stop The World, 那你们知道还有一个区域满了一会触发Fu ...
- docker-compose 搭建kafka集群
docker-compose搭建kafka集群 下载镜像 1.wurstmeister/zookeeper 2.wurstmeister/kafka 3.sheepkiller/kafka-manag ...
- FastAPI 学习之路(七)字符串的校验
系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...
- python中单引号、双引号和三引号
在python中字符串可以用双引号表示,也可以用单引号表示: str1 = 'hello world'str2 = "hello world" 这两种字符串的表示方法没有区别. p ...
- 【UE4 C++】DateTime、Timespan 相关函数
基于UKismetMathLibrary DateTime 相关函数 Timespan 运算操作相关函数见尾部附录 /** Returns the date component of A */ UFU ...
- VS2019 及 Visual Assist X 安装配置
Visual Studio 2019 安装 下载 https://visualstudio.microsoft.com/zh-hans/downloads/ 安装 设置 扩大 Solution Con ...
- 升级MySQL8.0的历险记
最近忙于Fighting的项目,所以笔耕有些松懈,实为不该. 刚好遇到需要从MySQL5.7.33升级到MySQL8.0.x的需求,于是记录一下整个升级过程,踩坑而过. 背景梗概:本地docker容器 ...
- 用Python画如此漂亮的专业插图 ?简直So easy!
本文整理自知乎问答,仅用于学术分享,著作权归作者所有.如有侵权,请联系我删文处理.多多转发,多多学习! 方法一 强烈推荐 Python 的绘图模块 matplotlib: python plottin ...
- uni-app使用wx-canvas实现微信小程序上显示地图map和坐标geo
源码 <template> <view class="echart-box"> <canvas class="ec-canvas" ...
- JMeter学习笔记--并发登录测试
账号密码读取文件 1.设置线程数为30,并发用户量就是30个用户同时登录 2.添加同步定时器 添加 Synchronizing Timer 同步定时器,为了阻塞线程,当线程数达到指定数量,再同时释放, ...