Codeforces 535C - Tavas and Karafs
2024-10-19 14:26:37
思路:对于满足条件的r,max(hl ,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 ;
}
最新文章
- 介绍几种SSIS部署方式
- #pg学习#postgresql的安装
- Mysql 基础1
- myeclipse6.5中使用Alt+/不自动提示的修改
- PHP错误The server encountered an internal error or misconfiguration and was unable to complete your re
- (转)基于即时通信和LBS技术的位置感知服务(三):搭建Openfire服务器+测试2款IM客户端
- 【C++11】新特性——Lambda函数
- HDU1251 统计难题(Trie)
- 英文:known good board ( KGB) / 中文:测试用标准板,黄金板
- 关于ExtJS必输框,多选项
- 移动端布局,C3新增属性
- 团队作业1——团队展示&;博客作业查重系统
- Android7.0 多窗口你值得拥有
- Python中的函数与变量
- hibernate多表查询封装实体
- 支持向量机SVM原理_python sklearn建模乳腺癌细胞分类器(推荐AAA)
- 批量将PowerDesigner中表字段由小写变成大写
- 关于super的理解,三篇文章支撑起来的
- Eclipse Maven项目报错3之找不到配置文件spring-servlet-context.xml
- intellij idea强制更新索引
热门文章
- Django初级手册1-项目和应用的创建与简单的数据库操作
- Web前端开发推荐阅读书籍、学习课程下载
- 25最短路径之Dijkstra算法
- 数据仓库基础(七)Informatica PowerCenter介绍
- Zookeeper学习记录(二):使用以及配置
- 怎样把QQ群降级(1000人降到200或500人,500人降到200)
- JDBC批量插入数据优化,使用addBatch和executeBatch
- c++中的字符集与中文
- 05: python中的函数
- ";1130-host ... is not allowed to connect to this MySql server";登录失败