题目传送门

 /*
题意:给定一个数列,求最大的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. Jenkins+appium+testng持续集成

    Create maven project in eclipseAdd Appium , Selenium dependancyAdd Test in TestNG testCreate TestNG ...

  2. 文件管理中心iOS版简介

    App Store地址:https://itunes.apple.com/cn/app/id1023365565?mt=8 文件管理中心-装机必备的文件管家,专业的rar-zip 解压工具,局域网看片 ...

  3. querying rpm database

    Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator al ...

  4. Robots协议应用与写法研究

  5. poj 1015 Jury Compromise(背包+方案输出)

    \(Jury Compromise\) \(solution:\) 这道题很有意思,它的状态设得很...奇怪.但是它的数据范围实在是太暴露了.虽然当时还是想了好久好久,出题人设了几个限制(首先要两个的 ...

  6. Springboot读取自定义的yml文件中的List对象

    Yml文件(novellist.xml)如下: novellist:   list:     - name: 笑傲江湖       type: 武侠       master: 令狐冲       a ...

  7. 浅谈HTTPS连接

    相信很多朋友都遇到过网页被强插广告的情况,好端端一个干净的页面,动不动就被插了个屠龙宝刀点击就送的小窗口,看着就心烦.这种网页劫持强插广告的现象,在中国非常常见,往往是运营商进行HTTP劫持所造成的. ...

  8. python selenium实现百度搜索

    1.环境 python2.7+selenium+phantomjs+linux 2.代码 #-*-coding:utf-8 -*- from selenium import webdriver fro ...

  9. 软件GUI测试中的关注点

    [摘要] 本文列数了软件黑盒测试过程中,在被测试软件中可能存在的常见软件问题.本文不会详细讨论基本的软件测试思想与常用技术,仅针对在软件黑盒测试过程中若干的问题做描述,并提供个人的参考测试意见与防范意 ...

  10. JS DOM1核心概要1

    节点:XML和HTML文档都是有节点构成的结构,每段标记都可以通过节点来表示: 节点类型: 元素节点(常用) 属性节点(常用) 文本节点 注释节点 文档节点 进程节点 文档类型节点 等... 了解节点 ...