http://codeforces.com/contest/535/problem/C
2 seconds
256 megabytes
standard input
standard output
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs issi = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such thatl ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
For each query, print its answer in a single line.
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
4
-1
8
-1
1 5 2
1 5 10
2 7 4
1
2
题意:给一个等差数列,基为a,差为b,每次能对m个值减一,给出范围l,m,和次数t,求最能是得有边为0的最大值;
题解:二分找到符合的位置;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<fstream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;
ll a,b,n,m,l,t;
ll slove(ll x)
{
ll ans=(a*+(l+x-)*b)*(x-l+)/;
return ans;
}
bool judge(ll x)
{
if(a+(x-)*b>t)return true;
if(slove(x)>t*m)return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cin>>a>>b>>n;
while(n--)
{
cin>>l>>t>>m;
if(a+(l-)*b>t)
{
cout<<-<<endl;continue;
}
ll L=l,R=1e9;
while(R-L>=)
{
ll mid=(R+L)>>;
if(judge(mid))
{
R=mid-;
}
else
{
L=mid+;
}
}
cout<<L-<<endl;
}
return ;
}
http://codeforces.com/contest/535/problem/C的更多相关文章
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
- http://codeforces.com/contest/555/problem/B
比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...
- http://codeforces.com/contest/610/problem/D
D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- http://codeforces.com/contest/536/problem/B
B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/838/problem/A
A. Binary Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- http://codeforces.com/contest/402/problem/E
E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces.com/contest/251/problem/C
C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- Python 多线程库总结
多线程库总结 基于线程的并行性 threading模块 下面是一些基础函数,函数包括: 函数 threading.active_count() threading.current_thread() t ...
- Spring Boot + Dubbo 可运行的例子源码-实现服务注册和远程调用
最近公司的一个分布式系统想要尝试迁移到Dubbo,项目本身是Spring Boot的,经过一些努力,最终也算是搭建起一个基础的框架了,放到这里记录一下.需要依赖一个外部的zookeeper. 源码地址 ...
- 转:【Java集合源码剖析】LinkedHashmap源码剖析
转载请注明出处:http://blog.csdn.net/ns_code/article/details/37867985 前言:有网友建议分析下LinkedHashMap的源码,于是花了一晚上时 ...
- 结队编程-基于gui的四则运算生成器
成员:卢少锐 201421123027.刘存201421033023 coding.net地址 1.需求分析:除了实现四则运算的功能外,还添加了计时器功能和语言选择功能 2.程序设计:这次作业是基于上 ...
- 201521123091 《Java程序设计》第4周学习总结
Java 第二周总结 第四周的作业. 目录 1.本章学习总结 2.Java Q&A 3.使用码云管理Java代码 4.PTA实验 1.本章学习总结 1.1 尝试使用思维导图总结有关继承的知识点 ...
- 团队作业4——第一次项目冲刺(Alpha版本) 2017.4.23
本次会议为第二次Scrum Meeting会议~ 由于本次会议项目经理召开时间为10:30,在五社区会五号楼召开,召开时长约30分钟,对昨天的工作进行了总结并分配了今天的任务. 1.站立式会议照片(拍 ...
- 201521123106 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- 201521123048 《Java程序设计》第9周学习总结
1. 本周学习总结 2. 书面作业 本次PTA作业题集异常 常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? ...
- Spring REST API + OAuth2 + AngularJS
http://www.baeldung.com/rest-api-spring-oauth2-angularjs 作者:Eugen Paraschiv 译者:http://oopsguy.com 1. ...
- CustomDialog——一个多功能、通用、可自定义的Dialog
CustomDialog--一个多功能.通用.可自定义的Dialog 依赖 compile 'com.github.SiberiaDante:CustomDialog:v1.0.1' 说明[Cus ...