二分搜索 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 ...
随机推荐
- Hadoop之HDFS文件操作
摘要:Hadoop之HDFS文件操作常有两种方式.命令行方式和JavaAPI方式.本文介绍怎样利用这两种方式对HDFS文件进行操作. 关键词:HDFS文件 命令行 Java API HD ...
- LeetCode题解(20)--Valid Parentheses
https://leetcode.com/problems/valid-parentheses/ 原题: Given a string containing just the characters ' ...
- Eclipse中设置编码的方法
Eclipse中设置编码的方式如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Java文件使用UTF-8编码.然而,Eclipse工作空间(workspace)的缺省字 ...
- Maven group, artifact or version defined in the pom file do not match the file ...
在把library上传到bintray空间的时候报以下错误 Could not upload to 'https://api.bintray.com/content/ping/maven/comm-a ...
- [原创] Karen and Supermarket 2
在回家的路上,凯伦决定到超市停下来买一些杂货. 她需要买很多东西,但因为她是学生,所以她的预算仍然很有限. 事实上,她只花了b美元. 超市出售N种商品.第i件商品可以以ci美元的价格购买.当然,每件商 ...
- 20170225-ALV tree 显示
1.写程序, 2.话屏幕9000,CALL SCREEN 9000.(双击屏幕进去画个容器就ok,+OK_CODE,+去掉注释) 3.处理好ALV 的PBO 初始化,处理用户事件PAO,user co ...
- console调试命令
一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...
- 使用proc接口例子【转】
本文转载自:http://blog.csdn.net/mike8825/article/details/52434666 版权声明:本文为博主原创文章,未经博主允许不得转载. 在上一篇的使用sys接口 ...
- 51Nod 1089 最长回文子串 V2 —— Manacher算法
题目链接:https://vjudge.net/problem/51Nod-1089 1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: ...
- POJ2914 Minimum Cut —— 最小割
题目链接:http://poj.org/problem?id=2914 Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Sub ...