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 二分查找+贪心的更多相关文章
- CF Tavas and Karafs (二分)
Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Tavas and Karafs 二分+结论
二分比较容易想到 #include<map> #include<set> #include<cmath> #include<queue> #includ ...
- CodeForces 535C Tavas and Karafs —— 二分
题意:给出一个无限长度的等差数列(递增),每次可以让从l开始的m个减少1,如果某个位置已经是0了,那么可以顺延到下一位减少1,这样的操作最多t次,问t次操作以后从l开始的最长0序列的最大右边界r是多少 ...
- 抄书(B - 二分查找)
抄书 (二分查找+贪心) 提示:二分查找一般写成非递归形式 时间复杂度:O(logn) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- 南理第八届校赛同步赛-F sequence//贪心算法&二分查找优化
题目大意:求一个序列中不严格单调递增的子序列的最小数目(子序列之间没有交叉). 这题证明贪心法可行的时候,可以发现和求最长递减子序列的长度是同一个方法,只是思考的角度不同,具体证明并不是很清楚,这里就 ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- #C++初学记录(贪心算法#二分查找)
D - Aggressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 < ...
- 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 ...
- River Hopscotch-[二分查找、贪心]
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
随机推荐
- First & First
First有记录则返回,否则返回null FirstOrDefault有记录则返回,否则NEW一个新的实体对象返回
- hdu 1044 Collect More Jewels(bfs+状态压缩)
Collect More Jewels Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- to_number,Extract oracle的关键字
to_number(Extract(year from 字段名)) 简介:获取时间字段的年份后转换为数字
- UVa11235 FrequentValues(RMQ)
Problem F: Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasi ...
- String.Format格式说明(转)
C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...
- 基数排序详解以及java实现
前言 基数排序(radix sort)又称桶排序(bucket sort),相对于常见的比较排序,基数排序是一种分配式排序,即通过将所有数字分配到应在的位置最后再覆盖到原数组完成排序的过程.我在上一篇 ...
- Angular JS 使用的注意事项
标签中ng-app,什么情况需要指定名称,什么时候又不需要呢? 1.ng-app="" <div ng-app="" ng-controller='myC ...
- JSON的解析
一:JSON字符串转换为JSON对象 JSON 最常见的用法之一,是从 web 服务器上读取 JSON 数据(作为文件或作为 HttpRequest),将 JSON 数据转换为 JavaScript ...
- WEB标准系列-HTML元素嵌套
转:http://www.smallni.com/element-nesting/ 先来看以下这样一段代码: <ul> <li><h4><a href=&qu ...
- Drupal 7.31 SQL注入漏洞利用具体解释及EXP
有意迟几天放出来这篇文章以及程序,只是看样子Drupal的这个洞没有引起多少重视,所以我也没有必要按着不发了,只是说实话这个洞威力挺大的.当然.这也是Drupal本身没有意料到的. 0x00 首 ...