题目传送门

 /*
题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1
二分搜索:搜索r,求出sum <= t * m的最大的r
详细解释:http://blog.csdn.net/libin56842/article/details/45082747
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
ll A, B, n, l, t, m; ll cal(ll x) {return A + (x - ) * B;} ll get_sum(ll l, ll r)
{
return (cal (l) + cal (r)) * (r - l + ) / ;
} int main(void) //Codeforces Round #299 (Div. 2) C. Tavas and Karafs
{
while (scanf ("%I64d%I64d%I64d", &A, &B, &n) == )
{
for (int i=; i<=n; ++i)
{
scanf ("%I64d%I64d%I64d", &l, &t, &m);
if (cal (l) > t) {puts ("-1"); continue;}
ll x = l; ll r = (t - A) / B + ;
while (x <= r)
{
ll mid = (x + r) / ;
if (get_sum (l, mid) <= t * m) x = mid + ;
else r = mid - ;
}
printf ("%d\n", r);
} } return ;
}

二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs的更多相关文章

  1. Codeforces Round #299 (Div. 1) A. Tavas and Karafs 水题

    Tavas and Karafs Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/prob ...

  2. 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

    题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...

  3. DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas

    题目传送门 /* DFS:按照长度来DFS,最后排序 */ #include <cstdio> #include <algorithm> #include <cstrin ...

  4. Codeforces Round #299 (Div. 2) D. Tavas and Malekas kmp

    题目链接: http://codeforces.com/problemset/problem/535/D D. Tavas and Malekas time limit per test2 secon ...

  5. Codeforces Round #299 (Div. 2) B. Tavas and SaDDas 水题

    B. Tavas and SaDDas Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/p ...

  6. Codeforces Round #299 (Div. 2) A. Tavas and Nafas 水题

    A. Tavas and Nafas Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/pr ...

  7. Codeforces Round #299 (Div. 1)C. Tavas and Pashmaks (凸壳)

    C. Tavas and Pashmaks   Tavas is a cheerleader in the new sports competition named "Pashmaks&qu ...

  8. Codeforces Round #299 (Div. 2) B. Tavas and SaDDas【DFS/*进制思维/位运算/一个数为幸运数,当且仅当它的每一位要么是4,要么是7 ,求小于等于n的幸运数个数】

    B. Tavas and SaDDas time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #299 (Div. 2)D. Tavas and Malekas

    KMP,先预处理按每个节点标记,扫一遍更新每个匹配位置,最后kmp判断是否有重合而且不相同的地方 注意处理细节,很容易runtime error #include<map> #includ ...

随机推荐

  1. appium 控件定位

    转自:http://www.2cto.com/kf/201410/340345.html AppiumDriver的各种findElement方法的尝试,尝试的目标应用是SDK自带的Notepad应用 ...

  2. windows下安装RubbitMq

    1.下载 下载 rabbitMQ :http://www.rabbitmq.com/download.html,安装rabbitmq需要erlang,下载erlang:http://www.erlan ...

  3. 正则表达式pattern的匹配格式

    0> 匹配 -------------------------------------------------------------------------------- (pattern)  ...

  4. java.lang.IllegalStateException: No instances available for localhost

    在SpringCloud的项目中,我们使用了自动配置的OAuth2RestTemplate,RestTemplate,但是在使用这些restTemplate的时候,url必须是服务的名称,如果要调用真 ...

  5. oracle监听器启动,实例启动

    1,su - oracle登录oracle用户 2,sqlplus / as sysdba登录oracle 3,show parameter service_names; 若正常输出servicena ...

  6. hdu 1963 Investment 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 题目意思:有 本金 money,还有一些股票的种类,第 i 种股票买入需要 value[i] 这 ...

  7. php判断某个变量是否存在

    sset— 检测变量是否设置,empty — 检查一个变量是否为空(是否存在也检测了,不存在或为空返回true)

  8. BZOJ_3049_[Usaco2013 Jan]Island Travels _状压DP+BFS

    BZOJ_3049_[Usaco2013 Jan]Island Travels _状压DP+BFS Description Farmer John has taken the cows to a va ...

  9. 【旧文章搬运】Windows句柄表分配算法分析(一)

    原文发表于百度空间,2009-03-30========================================================================== 阅读提示: ...

  10. [转载]文件过滤驱动 文件系统激活通知 IoRegisterFsRegistrationChange函数实现

    IoRegisterFsRegistrationChange 注册一个文件系统变动回调函数,用来被通知文件系统的激活和注销,激活是指第一次加载文件系统,当一个文件系统已经加载后,当加载一个同种文件系统 ...