C. Tavas and Karafs

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const int INF = 0x4fffffff;
const double EXP = 1e-;
const int MS = ;
const int SIZE = ; int main()
{
LL A,B,n;
LL L,T,M;
cin>>A>>B>>n;
for(LL i=;i<n;i++)
{
cin>>L>>T>>M;
LL minv=(L-)*B+A;
if(T<minv)
{
cout<<"-1"<<endl;
continue;
}
LL R=(T-minv)/B; int tl=L;
int tr=L+R+;
while((tr-tl)>) //二分查找用[a,b)使用方便,又不易出错。
{
LL mid=(tr+tl)>>;
LL sum=(mid-L+)*A+(mid+L-)*(mid-L+)/*B;
LL maxv=(mid-)*B+A; LL time=sum/M;
if(sum%M!=)
time++;
time=max(time,maxv);
if(time<=T)
tl=mid;
else
tr=mid;
}
cout<<tl<<endl;
}
return ;
}

C. Tavas and Karafs 二分查找+贪心的更多相关文章

  1. CF Tavas and Karafs (二分)

    Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. Tavas and Karafs 二分+结论

    二分比较容易想到 #include<map> #include<set> #include<cmath> #include<queue> #includ ...

  3. CodeForces 535C Tavas and Karafs —— 二分

    题意:给出一个无限长度的等差数列(递增),每次可以让从l开始的m个减少1,如果某个位置已经是0了,那么可以顺延到下一位减少1,这样的操作最多t次,问t次操作以后从l开始的最长0序列的最大右边界r是多少 ...

  4. 抄书(B - 二分查找)

    抄书  (二分查找+贪心) 提示:二分查找一般写成非递归形式 时间复杂度:O(logn) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  5. 南理第八届校赛同步赛-F sequence//贪心算法&二分查找优化

    题目大意:求一个序列中不严格单调递增的子序列的最小数目(子序列之间没有交叉). 这题证明贪心法可行的时候,可以发现和求最长递减子序列的长度是同一个方法,只是思考的角度不同,具体证明并不是很清楚,这里就 ...

  6. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  7. #C++初学记录(贪心算法#二分查找)

    D - Aggressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 < ...

  8. Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找

    The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 second ...

  9. River Hopscotch-[二分查找、贪心]

    Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...

随机推荐

  1. 第三百三十一天 how can I 坚持

    今天加了一天班,好累,还没吃晚饭,回来只吃了个泡面. 晚上回来的路上,在群里聊的倒是很happy,快笑死我了,仲宫二少,哈哈. 弟弟过两天要去见面,多聊聊,该结婚来. 还有,中午吃的肯德基,不好吃,可 ...

  2. CMake编译linux C++

    CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的 ...

  3. javascript日期格式化方法汇总

    本文给大家汇总介绍了javascript格式化日期时间的几种常用方法,个人对最后一种个性化输出时间比较有兴趣,基本上只要项目中能用到都是使用这种,推荐给小伙伴们. 方法一: ? 1 2 3 4 5 6 ...

  4. POJ1469COURSES(二分图匹配)

    裸的二分图匹配 题目poj.org/problem?id=1469 不解释:

  5. http://docwiki.embarcadero.com/RADStudio/XE7/en/Delphi_Data_Types

    http://docwiki.embarcadero.com/RADStudio/XE7/en/Delphi_Data_Types

  6. JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer

    Description Resource Path Location Type JavaServer Faces 2.2 can not be installed : One or more cons ...

  7. [Netbeans]为面板设置背景图片

    与AndroidStudio等类似IDE不同,在Netbeans开发桌面程序时,不可以直接通过src=@drawable 等方法为窗口设置背景图片.这里介绍一种简便的方法: 1:首先,拖动一个面板到f ...

  8. 当类库项目中无法使用Application.StartupPath

    通常我们WinForm编程时,要获取程序当前运行的文件夹路径会用Application.StartupPath ,但是Application.StartupPath在编写类库项目时却无法使用,因为我们 ...

  9. android wifi总结

    大致可以分为四个主要的类ScanResult wifiConfiguration WifiInfo WifiManager (1)ScanResult,主要是通过wifi 硬件的扫描来获取一些周边的w ...

  10. PPAS上运行pg_dump经过II

    这一次,我用三台机器. 其他步骤和<PPAS上运行pg_dump经过>中讲到的一样. http://www.cnblogs.com/gaojian/p/3195321.html 只是,pg ...