CF 535c Tavas and Karafs
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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 ≤ r and 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.
Input
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.
Output
For each query, print its answer in a single line.
Sample Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
4
-1
8
-1
1 5 2
1 5 10
2 7 4
1
2
定理 序列h1,h2,...,hn 可以在t次时间内(每次至多让m个元素减少1) 全部减小为0 当且仅当
max(h1, h2, ..., hn) <= t && h1 + h2 + ... + hn <= m*t
然后用二分来做
网上的代码
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 12345678
#define M 1234 long long a,b,n,l,t,m; int main()
{
while(~scanf("%lld%lld%lld",&a,&b,&n))
{
for(int i=;i<n;i++)
{
scanf("%lld%lld%lld",&l,&t,&m);
if(a+(l-)*b>t)
{
puts("-1");
continue;
}
long long ll=l,r=(t-a)/b+,mid; while(ll<=r)
{
mid=(ll+r)/;
if( (*a+(mid+l-)*b)*(mid-l+)/ <=t*m)
{
ll=mid+;
}
else
{
r=mid-;
}
}
cout<<ll-<<endl;
}
} return ;
}
我的代码
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 12345678
#define M 1234 long long a,b,n,l,t,m; int main()
{
while(~scanf("%lld%lld%lld",&a,&b,&n))
{
for(int i=;i<n;i++)
{
scanf("%lld%lld%lld",&l,&t,&m);
if(a+(l-)*b>t)
{
puts("-1");
continue;
}
long long ll=l,r=(t-a)/b+,mid; while(ll<=r)
{
mid=(ll+r)/;
if( (*a+(mid+l-)*b)*(mid-l+)/ <=t*m
&& (*a+(mid++l-)*b)*(mid+-l+)/ >t*m)
//这里wa了一次, 把 > 写成了 >= ,
{
break;
}
else if( (*a+(mid+l-)*b)*(mid-l+)/ <=t*m)
{
ll=mid+;
}
else
{
r=mid-;
}
}
cout<<mid<<endl;
}
} return ;
}
CF 535c Tavas and Karafs的更多相关文章
- Codeforces 535C - Tavas and Karafs
535C - Tavas and Karafs 思路:对于满足条件的r,max(hl ,hl+1 ,hl+2 ,......,hr )<=t(也就是hr<=t)且∑hi<=t*m.所 ...
- CodeForces 535C Tavas and Karafs —— 二分
题意:给出一个无限长度的等差数列(递增),每次可以让从l开始的m个减少1,如果某个位置已经是0了,那么可以顺延到下一位减少1,这样的操作最多t次,问t次操作以后从l开始的最长0序列的最大右边界r是多少 ...
- CF Tavas and Karafs (二分)
Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- C. Tavas and Karafs 二分查找+贪心
C. Tavas and Karafs #include <iostream> #include <cstdio> #include <cstring> #incl ...
- 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) C. Tavas and Karafs
题目传送门 /* 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 二分搜索:搜索r,求出sum <= t * m的最大的r 详细解释:http:/ ...
- codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)
题意:一个等差数列,首项为a,公差为b,无限长.操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少. 这么一个简单题吞 ...
- Tavas and Karafs 二分+结论
二分比较容易想到 #include<map> #include<set> #include<cmath> #include<queue> #includ ...
- 【Codeforces Round #299 (Div. 2) C】 Tavas and Karafs
[链接] 我是链接,点我呀:) [题意] 给你一个规则,让你知道第i根萝卜的高度为si = A+(i-1)*B 现在给你n个询问; 每次询问给你一个固定的起点l; 让你找一个最大的右端点r; 使得l. ...
随机推荐
- Android 8.0 adb shell dumpsys activity activities | findstr mFocusedActivity 获取当前的 activity 显示空的
adb shell dumpsys activity activities | findstr mFocusedActivity Android 7.0 现象: Android 8.0 现象: 改用: ...
- pytorch中torch.unsqueeze()函数与np.expand_dims()
numpy.expand_dims(a, axis) Expand the shape of an array. Insert a new axis that will appear at the a ...
- Codeforces Round #417 (Div. 2) 花式被虐
A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #415 (Div. 2) 翻车啦
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 九度oj 题目1207:质因数的个数
题目描述: 求正整数N(N>1)的质因数的个数. 相同的质因数需要重复计算.如120=2*2*2*3*5,共有5个质因数. 输入: 可能有多组测试数据,每组测试数据的输入是一个正整数N,(1&l ...
- Redis常见配置redis.conf
redis的配置文件.相信学过SSH或SSM的读者都知道,配置文件的使用在当下开发已十分普遍,希望大家要熟悉习惯这 种开发方式,废话不多说,来开始我们今天的内容吧. 首先得找到 redis 的配置文件 ...
- #ifdef endif 用法
"#ifdef 语句1 程序2 #endif“ 可翻译为:如果宏定义了语句1则程序2. 作用:我们可以用它区隔一些与特定头文件.程序库和其他文件版本有关的代码. 代码举例:新建define. ...
- mybatis配置报错(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)
如下报错:解决方案:要按照提示的顺序添加属性,(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrappe ...
- Java线程池快速学习教程
1. Java线程池 线程池:顾名思义,用一个池子装载多个线程,使用池子去管理多个线程. 问题来源:应用大量通过new Thread()方法创建执行时间短的线程,较大的消耗系统资源并且系统的响应速度变 ...
- 维修队列(bzoj 1500)
Description Input 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目.第2行包含N个数字,描述初始时的数列.以下M行,每行一 ...