Q(这个题提交失败,但样例是对的QAQ,好像服务器有问题,不能提交)
2017-05-01 22:02
267 查看
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
Input
Output
Input
Output
题目分析
这个题目蛮难读的,谷歌翻译还不如自己翻译QAQ
现在给你一个以A为基,B为公差的等差数列(无现长),其中有N个询问。
对于N个询问,每个询问有三个元素,l,t,m;
表示我们现在有t次操作,每次可以选择m个数将其都-1.
现在问你能够使得以l为起点,r为终点最远的r,区间【l,r】所有数都减少为0.解题思路
显然这个终点r越远,需要的操作就越多,其具有单调性,那么我们二分终点。进行判断。
如果当前终点可行,那么让这个终点更远一些,否则就更近一些。
源代码
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long A,B,n;
long long get(long long mid)
{
return A+(mid-1)*B;
}
long long gs(long long l,long long r)
{
long long rr=(A+A+(r-1)*B)*r/2;
long long lll=(A+A+(l-2)*B)*(l-1)/2;
return rr-lll;
}
int main()
{
while(~scanf("%I64d%I64d%I64d",&A,&B,&n))
{
for(long long i=0;i<n;i++)
{
long long s,t,m;
scanf("%I64d%I64d%I64d",&s,&t,&m);
long long left=s;
long long right=1000000000;
long long ans=-1;
while(right-left>=0)
{
long long mid=(right+left)/2;
if(get(mid)>t)rig
4000
ht=mid-1;
else
{
if(gs(s,mid)>m*t)
{
right=mid-1;
}
else
{
ans=mid;
left=mid+1;
}
}
}
printf("%d\n",ans);
}
}
}
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
Input
2 1 4 1 5 3 3 3 10 7 10 2 6 4 8
Output
4 -1 8 -1
Input
1 5 2 1 5 10 2 7 4
Output
12
题目分析
这个题目蛮难读的,谷歌翻译还不如自己翻译QAQ
现在给你一个以A为基,B为公差的等差数列(无现长),其中有N个询问。
对于N个询问,每个询问有三个元素,l,t,m;
表示我们现在有t次操作,每次可以选择m个数将其都-1.
现在问你能够使得以l为起点,r为终点最远的r,区间【l,r】所有数都减少为0.解题思路
显然这个终点r越远,需要的操作就越多,其具有单调性,那么我们二分终点。进行判断。
如果当前终点可行,那么让这个终点更远一些,否则就更近一些。
源代码
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long A,B,n;
long long get(long long mid)
{
return A+(mid-1)*B;
}
long long gs(long long l,long long r)
{
long long rr=(A+A+(r-1)*B)*r/2;
long long lll=(A+A+(l-2)*B)*(l-1)/2;
return rr-lll;
}
int main()
{
while(~scanf("%I64d%I64d%I64d",&A,&B,&n))
{
for(long long i=0;i<n;i++)
{
long long s,t,m;
scanf("%I64d%I64d%I64d",&s,&t,&m);
long long left=s;
long long right=1000000000;
long long ans=-1;
while(right-left>=0)
{
long long mid=(right+left)/2;
if(get(mid)>t)rig
4000
ht=mid-1;
else
{
if(gs(s,mid)>m*t)
{
right=mid-1;
}
else
{
ans=mid;
left=mid+1;
}
}
}
printf("%d\n",ans);
}
}
}
相关文章推荐
- Linux下Eclipse配置安装 PyDev(Pydev插件一直不能成功,安装这个插件失败的问题)
- java代码=========这个代码还是有问题的。不能实现功能呀
- 好像博问不能回复了,看似是某个脚本错误阻止了提交。可有此事?
- github首次提交项目到服务器失败解决方法
- 表单元素disabled禁用后不能自动提交到服务器
- 认证失败: 不能认证到服务器: 被拒绝的 Basic 挑战
- java:邮件发送失败总结(只是外网服务器有问题)
- 工作中碰到的js问题(disabled表单元素不能提交到服务器)
- phpstorm 下配置 apache服务器的方法(解决 post不能正确提交到php的问题)
- Linux下Eclipse配置安装 PyDev(Pydev插件一直不能成功,安装这个插件失败的问题)
- Linux下Eclipse配置安装 PyDev(Pydev插件一直不能成功,安装这个插件失败的问题)
- 说不能确认服务器完全确认域名 localhost.localdoman 这个问题怎么解决
- SVN服务器提交失败 commit failed (details follow)
- ssh以密钥的方式登录服务器时,只要有密钥可以登服务器,如果有密钥和公钥同时存在(在公钥没问题的情况下可以),但如果公钥有问题,就不能登录成功
- select option 不可选,对于置于disable 提交服务器不能获取值的解决办法
- Ubuntu:SVN认证失败: 不能认证到服务器: 被拒绝的 Basic 挑战
- SVN 无法连接服务器 不能查看日志 不能提交的代码 解决办法
- URL不能过长,否则summit方法提交失败
- 我这个小白又来了,最近在尝试运行网上的开源代码,服务器连接报错了好像,求帮助?
- php ajax提交数据 在本地可以执行,而在服务器不能执行