思路:二分答案,然后模拟消灭石头的过程;

如果单纯的暴力模拟的话,肯定会T的;

所以要用到一定的技巧来维护;

在网上看到大神们用O(n)的复杂度来优化,真心orz;

原理是这样的:用一个变量sum_2存前面所有的对当前石头造成影响的冲击波的损失的能量和;

所以对于当前的石头所需要的新的冲击波的数量为:(当前石头的能量值-前面有影响的冲击波数*能量x+sum_2)/能量x+1;

然后就是维护sum_2了!

维护sum_2要利用这个公式:(x+1)^2=x^2+2*x+1;

 #include<iostream>
#define maxn 50005
#define ll long long
using namespace std;
ll cnt[maxn];
ll num[maxn];
int n,k,t;
bool check(ll x)
{
ll sum_2=,sum_1=,sum=,ans=;
int j=n-;
for(int i=n-;i>=;i--)
{
if(j>i)
{
while((j-i)*(j-i)>=x)
{
sum_2-=cnt[j]*(j-i-)*(j-i-);
sum_1-=cnt[j]*(j-i-);
sum-=cnt[j];
j--;
}
}
sum_2+=*sum_1+sum;
sum_1+=sum;
ll y=num[i]-sum*x+sum_2;
if(y<)cnt[i]=;
else cnt[i]=y/x+;
sum+=cnt[i];
ans+=cnt[i];
}
return ans<=k;
} int main()
{
cin>>t;
while(t--)
{
cin>>n>>k;
for(int i=;i<n;i++)cin>>num[i];
ll l=,r=1e12;
while(l<r)
{
ll mid=(l+r)>>;
if(check(mid))r=mid;
else l=mid+;
}
cout<<l<<endl;
}
return ;
}

hdu 3717的更多相关文章

  1. hdu 3717 二分+队列维护

    思路:已知当前的总长度和为len,当前的伤害为sum,伤害次数为 num.那么对下一个点的伤害值sum=sum+2*len+num: 这个是通过(x+1)^2展开化简就能得到. #include< ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. asp.net 编写验证码

    首先准备一个类来实现对验证码的绘制功能. createcode.cs using System; using System.Collections.Generic; using System.Linq ...

  2. Java .Net C++ RSA 加密

    原文:http://www.codeproject.com/Articles/25487/Cryptographic-Interoperability-Keys DEMO: JAVA .Net C++

  3. Swf Decrypt详解

    http://www.2cto.com/Article/201507/414477.html 攻击在持续,攻击的技术在演进.防御者需要持续的跟进研究和投入.最近Flash 0day频繁出现,将我们更多 ...

  4. SQL Server(基本) 关键字的使用 一

    一, 基础关键字 -- 使用介绍 1,select 的使用(select 结果集) SELECT 列名称 FROM 表名称 以及: (*)是选取所有列的快捷方式. SELECT * FROM 表名称 ...

  5. try catch异常捕获

    格式为: try            {                int i = int.Parse(Console.ReadLine());           //容易发生错误的语句    ...

  6. 40个Java集合面试问题和答案【中】【转载】

    接上文:http://www.cnblogs.com/xujianbo/p/5148075.html   16.UnsupportedOperationException是什么? Unsupporte ...

  7. unity3d环境安装指南: Unity 4.5.5 + Visual Studio 2010

    1. UnitySetup-4.5.5.exe 官网下载最新版本4.X 安装exe文件 2. Unity 4.x Pro Patch.exe 复制exe到安装目录下 C:\Program Files ...

  8. 包含为 HTTP 定义的状态代码的值(枚举)

    using System; namespace System.Net { // 摘要: // 包含为 HTTP 定义的状态代码的值. public enum HttpStatusCode { // 摘 ...

  9. C语言 goto, return等跳转

    C语言 goto, return等跳转 Please don't fall into the trap of believing that I am terribly dogmatical about ...

  10. Menu bar missing from ClearCase Explorer

    See following links: Menu bar missing from ClearCase Explorer Understanding the Rational ClearCase E ...