博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷 1485 火枪打怪
阅读量:4576 次
发布时间:2019-06-08

本文共 1447 字,大约阅读时间需要 4 分钟。

【题解】

  二分答案+差分

  本题要求出尽量小的威力值P,很容易想到二分答案

  而本题难点在于二分答案之后的检验。每发子弹对一个区间造成影响,我们可以尝试使用差分。但每发子弹对区间不同位置的影响是不同的。因此我们可以用多阶差分。

a3 0 -p -p+1 -p+4 -p+9 ... -p+s2 0 0 0 0
a2 0 0 1 3 5 ... 2s-1 p-s2 0 0 0
a1 0 0 1 2 2 ... 2 p-(s+1)2+2 -p+s2 0 0
a0 0 0 1 1 0 ... 0 p-(s+1)2 -2p+2s2+2s-1
p-s2 0

  

1 #include
2 #include
3 #include
4 #define LL long long 5 using namespace std; 6 const int maxn=1000010; 7 LL n,k,l,r,mid,ans,a0[maxn],a1[maxn],a2[maxn],a3[maxn],b[maxn],b2[maxn]; 8 inline LL read(){ 9 LL k=0,f=1; char c=getchar();10 while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();11 while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();12 return k*f;13 }14 inline LL max(LL x,LL y){
return x>y?x:y;}15 inline LL min(LL x,LL y){
return x
k) return 0;27 a3[i]-=num*x;28 a0[i+1]+=num; a0[i+2]+=num;29 a0[min(i+stop,n)+1]+=(x-(stop+1)*(stop+1))*num;30 a0[min(i+stop,n)+2]+=(-2*x+stop*stop+(stop+1)*(stop+1)-2)*num;31 a0[min(i+stop,n)+3]-=(stop*stop-x)*num;32 }33 return cnt<=k;34 }35 int main(){36 n=read(); k=read();37 for(int i=n;i;i--) b[i]=b2[i]=read()+1,r=max(r,b[i]+1LL*(i-1)*(i-1));//先把数组倒过来,方面后面的差分 38 l=0; r<<=1;39 while(l+1
>1)) r=mid; else l=mid;40 return printf("%lld\n",r),0;41 }
View Code

 

转载于:https://www.cnblogs.com/DriverLao/p/8044545.html

你可能感兴趣的文章
怎么拿到url地址?后的某个参数值
查看>>
android中如何在代码中直接设置View的layout_weight属性
查看>>
hdu 1853 Cyclic Tour(费用流OR二分图最佳匹配,5级)
查看>>
js 对url进行某个参数的删除,并返回url
查看>>
Windows7装Linux虚拟机
查看>>
SQL 操作结果集 -并集、差集、交集、结果集排序
查看>>
linux上搭建nginx+php+mysql环境详细讲解
查看>>
RemoveDuplicatesFromSortedArrayI II,移除有序数组里的重复元素以及移除数组里的某个元素...
查看>>
Minimum Depth of Binary Tree,求树的最小深度
查看>>
解决Web部署 svg/woff/woff2字体 404错误
查看>>
fiddler 抓取 nodejs
查看>>
1.Nginx服务应用
查看>>
MySQL基础
查看>>
凹凸贴图与法线贴图
查看>>
sqlserver跨服务器数据库sql语句
查看>>
设计模式-结构型模式,外观模式(6)
查看>>
Trie模版
查看>>
2018HDU多校训练-3-Problem F. Grab The Tree
查看>>
2016012032四则运算网页版结对项目报告
查看>>
边工作边刷题:70天一遍leetcode: day 45
查看>>