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 ...
随机推荐
- CSS照片墙
<!doctype html><html><head><meta charset="utf-8"><title>CSS照 ...
- 【Linux部署 · JDK】在linux系统安装jdk
1,检查是否安装jdk echo $JAVA_HOME 或者java -version 2,查看操作系统,很明显这是一个相当old的操作系统,i686是32位操作系统. 3,在oracle ...
- poj 2553 强连通
题意:给出一个有向图,定义:若节点v所有能到达的点{wi},都能反过来到达v,那么称节点v是sink.题目要求所有的sink点. 思路:强连通缩点找出出度为零的点,输出即可. 这题主要问题是读题,了解 ...
- JQuery实用技巧--学会你也是大神(1)——插件的制作技巧
前 言 JRedu 学习之前,首先我们需要知道什么是JQuery? JQuery是一个优秀的javascript框架. JQuery是继Prototype之后又一个优秀的Javascript框架 ...
- 个人作业3——个人总结(Alpha阶段)。
一:个人总结: 陆续几周以及加上上上一周的Alpha冲刺阶段,完成了实验室故障报修系统的基础框架以及内容.这个过程苦中有乐,或许苦中寻乐更加恰当,以一个小组团队的形式来完成这个项目,我们大家就变成了一 ...
- 团队作业4——第一次项目冲刺(Alpha版本) Day6
首先和助教及老师表示抱歉,博客确实当时就写了,但是一直不算写好,因为这几天卡住了,预计实现的功能实现不了,进度跟不上,现在也在寻求解决方法. 1.站立式会议: 2. Leangoo任务分解图: 3.任 ...
- 201521123071《Java程序设计》第1周学习总结
1. 本章学习总结 通过本周的学习,对java的一些语法以及java的发展史有了一定的基础认识,也了解了JDK的安装,以及环境变量定义和配置等知识.还有对码云,Markdown等的使用,大大方便了我们 ...
- bom是什么?
- FTP下载时连接正常获取不到数据
今天项目中要下载快钱的对账单,快钱对账单文件的FTP服务器是Unix系统,connectServer方法中已连接成功,reply code:220. 但是问题是download方法中的ftpClien ...
- Oracle日期时间操作大全
本文出自:http://www.cnblogs.com/hl3292/archive/2010/11/03/1868159.html oracle sql日期比较: 共三部分: 第一部分:oracle ...