codeforces535C:Tavas and Karafs(二分)
来源:互联网 发布:java底层书籍 编辑:程序博客网 时间:2024/06/11 18:32
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ rand sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
For each query, print its answer in a single line.
2 1 41 5 33 3 107 10 26 4 8
4-18-1
1 5 21 5 102 7 4
12
英语渣渣看题都看半天
首先给出a,b,n
这是一个由a开头,b为公差,长度无限的等差数列
然后n个询问
输入l,t,m
取这个数列从l开始,m个数,每一次这个数列中所有的数字-1
当首尾变成0的时候,可以向后移,问最后t次之后,最长的0序列的右边界是多少
那么我们首先可以确定,对于这个最终的序列而言,假设右边界为r
那么max(h1,h2,...hr)<=t && h1+h2+...hr<=t*m
对于这两个条件,我们进行二分即可
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define ls 2*i#define rs 2*i+1#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,x) memset(a,x,sizeof(a))#define w(a) while(a)#define LL long longconst double pi = acos(-1.0);#define Len 63#define mod 19999997const int INF = 0x3f3f3f3f;LL a,b,n;LL l,t,m;LL cal(LL x){ return a+(x-1)*b;}LL getsum(LL r){ return (cal(r)+cal(l))*(r-l+1)/2;}int main(){ LL i,j,k,maxn; w(~scanf("%I64d%I64d%I64d",&a,&b,&n)) { w(n--) { scanf("%I64d%I64d%I64d",&l,&t,&m); if(cal(l)>t) { printf("-1\n"); continue; } LL ll = l,lr = (t-a)/b+1,mid; w(ll<=lr) { LL mid = (ll+lr)/2; if(getsum(mid)<=t*m) ll = mid+1; else lr = mid-1; } printf("%d\n",ll-1); } } return 0;}
- codeforces535C:Tavas and Karafs(二分)
- codeforces535C:Tavas and Karafs(二分)
- codeforces535C:Tavas and Karafs(二分)
- codeforces535C:Tavas and Karafs(二分)
- Codeforces 535C Tavas and Karafs(二分)
- Codeforces 535C Tavas and Karafs(二分)
- 二分 Tavas and Karafs:CodeForces 535C
- Codeforces 535C : Tavas and Karafs(二分)
- Codeforces 535C Tavas and Karafs(二分)
- Q-Tavas and Karafs
- Codeforces 536A Tavas and Karafs 二分+结论
- Codeforces Round #299 (Div. 2) Tavas and Karafs(二分)
- Codeforcess 535C Tavas and Karafs【二分+思维】
- Codeforcess 535C Tavas and Karafs【二分+数据处理】
- Codeforces Round #299 (Div. 1) A. Tavas and Karafs(二分)
- Codeforces Round #299 (Div. 2) C. Tavas and Karafs 二分搜索+数列
- Codeforces 535C Tavas and Karafs
- [Codeforces 535B]Tavas and Karafs
- HTML5系列(二十一)画布(变形)
- Ext4 关于表单中fieldset错位的问题
- Html5系列(十九) canvas 弧形描边渐变
- Heap sort
- CStringArray
- codeforces535C:Tavas and Karafs(二分)
- C-回文[顺序表]
- LeetCode 104 Maximum Depth of Binary Tree
- 如何通过dba_hist_active_sess_history分析历史数据库性能问题
- MyBatis学习总结(一)——MyBatis快速入门
- Python GUI 08----Scale
- Html5系列(十八) canvas 径向渐变2
- Multiplication Puzzle POJ 1651
- 33-判断一个字符串中出现的字符的个数