535C - Tavas and Karafs

思路:对于满足条件的r,max(h,hl+1 ,hl+2 ,......,hr )<=t(也就是hr<=t)且∑hi<=t*m。所以通过这个条件二分找出最大的r。

二分的下界为1,上界为使得hi等于t的i(hi=t    ==>    a+(i-1)*b=t    ==>    i=(t-a)/b+1)

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset((a),(b),sizeof(a))
const int N=1e6+;
int a,b,n;
int l,t,m;
ll cal(int i){return (ll)a+(ll)(i-)*b;} bool check(ll r)
{
if((cal(l)+cal(r))*(r-l+)/>(ll)m*t)return false;
return true;
} int main()
{ scanf("%d%d%d",&a,&b,&n); while(n--)
{
scanf("%d%d%d",&l,&t,&m);
if(cal(l)>t)printf("-1\n");
else
{
ll L=l,R=(t-a)/b+,m=(L+R)>>;
while(L<=R)
{
if(check(m))L=m+;
else R=m-;
m=(L+R)>>;
}
printf("%d\n",m);
}
}
return ;
}

最新文章

  1. 介绍几种SSIS部署方式
  2. #pg学习#postgresql的安装
  3. Mysql 基础1
  4. myeclipse6.5中使用Alt+/不自动提示的修改
  5. PHP错误The server encountered an internal error or misconfiguration and was unable to complete your re
  6. (转)基于即时通信和LBS技术的位置感知服务(三):搭建Openfire服务器+测试2款IM客户端
  7. 【C++11】新特性——Lambda函数
  8. HDU1251 统计难题(Trie)
  9. 英文:known good board ( KGB) / 中文:测试用标准板,黄金板
  10. 关于ExtJS必输框,多选项
  11. 移动端布局,C3新增属性
  12. 团队作业1——团队展示&amp;博客作业查重系统
  13. Android7.0 多窗口你值得拥有
  14. Python中的函数与变量
  15. hibernate多表查询封装实体
  16. 支持向量机SVM原理_python sklearn建模乳腺癌细胞分类器(推荐AAA)
  17. 批量将PowerDesigner中表字段由小写变成大写
  18. 关于super的理解,三篇文章支撑起来的
  19. Eclipse Maven项目报错3之找不到配置文件spring-servlet-context.xml
  20. intellij idea强制更新索引

热门文章

  1. Django初级手册1-项目和应用的创建与简单的数据库操作
  2. Web前端开发推荐阅读书籍、学习课程下载
  3. 25最短路径之Dijkstra算法
  4. 数据仓库基础(七)Informatica PowerCenter介绍
  5. Zookeeper学习记录(二):使用以及配置
  6. 怎样把QQ群降级(1000人降到200或500人,500人降到200)
  7. JDBC批量插入数据优化,使用addBatch和executeBatch
  8. c++中的字符集与中文
  9. 05: python中的函数
  10. &quot;1130-host ... is not allowed to connect to this MySql server&quot;登录失败