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. ...
随机推荐
- UVa 10534 DP LIS Wavio Sequence
两边算一下LIS就出来了,因为数据比较大,所以需要二分优化一下. #include <iostream> #include <cstdio> #include <cstr ...
- windons杀死8080进程
1,netstat -aon|findstr "8080" //8080端口号 2,taskkill -PID 2976 -F //2976 ,8080端口号对应的进程号
- Jmeter接口测试-简单分析结果数、聚合报告以及图形结果(二)
简单分析结果数.聚合报告以及图形结果 结果树 取样器结果:返回值报200,表示执行接口调试成功 请求:发送的数据 响应数据:返回的数据 Thread Name:线程组名称 Sample Start: ...
- xtu数据结构 G. Count the Colors
G. Count the Colors Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Jav ...
- Convolution Fundamental I
Convolution Fundamental I Foundations of CNNs Learning to implement the foundational layers of CNN's ...
- ASP.NET(五):ASP.net实现真分页显示数据
导读:在上篇文章中,介绍了用假分页实现数据的分页显示 ,而避免了去拖动滚动条.但,假分页在分页的同时,其实是拖垮了查询效率的.每一次分页都得重新查询一遍数据,那么有没有方法可以同时兼顾效率和分页呢,那 ...
- MySQL容量规划之tcpcopy应用之道
官方文档:https://github.com/session-replay-tools/mysql-replay-module tcpcopy可以将正式环境上来自客户端的请求复制一份到测试端并复现, ...
- RHEL7网卡命名规则
systemd 和 udev 引入了一种新的网络设备命名方式:一致网络设备命名(CONSISTENT NETWORK DEVICE NAMING).根据固件.拓扑.位置信息来设置固定名字,带来的好处是 ...
- Java面向对象三大特征
封装: 首先,属性可用来描述同一类事物的特征, 行为可描述一类事物可做的操作,封装就是要把属于同一类事物的共性(包括属性与行为)归到一个类中,以方便使用.比如人这个东东,可用下面的方式封装:人{ 年龄 ...
- python 列表 字符串 转换
列表转字符串python中的列表l = ['1','2','3','4']转成str型'1,2,3,4'','.join(l)这个方法,列表里都是字符串的话可以这样用.列表里是整数的情况可以用: &g ...