二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs
/*
题意:给定一个数列,求最大的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的更多相关文章
- 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 ...
- 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas
题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...
- DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
题目传送门 /* DFS:按照长度来DFS,最后排序 */ #include <cstdio> #include <algorithm> #include <cstrin ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #299 (Div. 2)D. Tavas and Malekas
KMP,先预处理按每个节点标记,扫一遍更新每个匹配位置,最后kmp判断是否有重合而且不相同的地方 注意处理细节,很容易runtime error #include<map> #includ ...
随机推荐
- GitExtensions 官方手册(英文)
在线版本(最新版):https://git-extensions-documentation.readthedocs.io/en/latest/ PDF版本(版本号 2.48):http://pan. ...
- 组合模式(遍历树,file基表示文件也表示文件夹)
组合模式多个对象形成树形结构以表示“整体--部分”的结构层次.组合模式对单个对象(即叶子对象)和组合对象(即容器对象)的使用具有一致性. 组合模式又可以称为“合成模式“ 或 ”整体-部分模式”,属于对 ...
- js-easyUI格式化时间
formatter : function(value, row) { if(value != null){ var date = new Date(value); var y = date.getFu ...
- vue 数组和对象渲染问题
vue 数组和对象渲染问题 最近项目有点忙碌,遇到好多问题都没有总结(╥﹏╥),在开发过程中,取vuex中的数组渲染完成之后,再次修改数组的值,数据更新了,但是视图并没有更新.以为是数组更新的问题,后 ...
- easyui 在日期不满足要求的情况下,让修改链接不可点,或者修改消失
*****略***** columns:[[ {field:'id',checkbox:true}, {field:'mDate',width:10,title:'菜单日期',align:'left' ...
- 简易五子棋 V1.1.0
main.cpp #include "fivechess.cpp" int main() { fivechess a; a.RunGame(); getchar(); return ...
- skynet源码阅读<1>--lua与c的基本交互
阅读skynet的lua-c交互部分代码时,可以看到如下处理: struct skynet_context * context = lua_touserdata(L, lua_upvalueindex ...
- 机器学习 Hidden Markov Models 3
Viterbi Algorithm 前面我们提到过,HMM的第二类问题是利用HMM模型和可观察序列寻找最有可能生成该观察序列的隐藏变量的序列.简单来说,第一类问题是通过模型计算生成观察序列的概率,而第 ...
- 在Service里调用AlertDialog
用常规的方法在AlertDialog的时候,会报错,大意是「can not add window in this view」. 原因是Service是没有界面的,只有Activity才能添加界面. 解 ...
- NIO知识摘录
在 JDK 1. 4 中 新 加入 了 NIO( New Input/ Output) 类, 引入了一种基于通道和缓冲区的 I/O 方式,它可以使用 Native 函数库直接分配堆外内存,然后通过一个 ...