Forest Gathering

 
Problem code: FORESTGA
 
 

All submissions for this problem are available.

Read problems statements in Mandarin ChineseRussian and Vietnamese as well.

Chef is the head of commercial logging industry that recently bought a farm containing N trees. You are given initial height of the i-th tree by Hi and the rate of growth of height as Ri meters per month. For simplicity, you can assume that all the trees are perfect cylinders of equal radius. This allows us to consider only the height of trees when we talk about the amount of wood.

In Chef's country, laws don't allow one to cut a tree partially, so one has to cut the tree completely for gathering wood. Also, laws prohibit cutting trees of heights (strictly) lower than L meters.

Today Chef received an order of W meters (of height) of wood. Chef wants to deliver this order as soon as possible. Find out how minimum number of months he should wait after which he will able to fulfill the order. You can assume that Chef's company's sawing machines are very efficient and take negligible amount of time to cut the trees.

Input

There is a single test case per test file.

The first line of the input contains three space separated integers NW and L denoting the number of trees in the farm, the amount of wood (in meters) that have to be gathered and the minimum allowed height of the tree to cut.

Each of next N lines contain two space separated integers denoting Hi and Ri respectively.

Output

Output a single integer denoting the number of months that have to pass before Chef will be able to fulfill the order.

Constraints

  • 1 ≤ N ≤ 105
  • 1 ≤ WL ≤ 1018
  • 1 ≤ HiRi ≤ 109

Subtasks

  • Subtask #1 [40 points]: 1 ≤ NWL ≤ 104
  • Subtask #2 [60 points]: No additional constraints

Example

Input:
3 74 51
2 2
5 7
2 9 Output:
7

Explanation

After 6 months, heights of each tree will be 1447 and 56 respectively. Chef is allowed to cut only the third tree, sadly it is not enough to fulfill an order of 74 meters of wood.

After 7 months, heights of each tree will be 1654 and 65 respectively. Now Chef is allowed to cut second and third trees. Cutting both of them would provide him 119 meters of wood, which is enough to fulfill the order.

题意:给你n棵数,首先给你三个树,树的数量n,需要砍的长度w,树的最小砍伐高度l;

   n行,起始高度和每天增加长度;

思路:二分查找答案,防止爆long long 用减法;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 100000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
struct is
{
ll b,inc;
}a[N];
ll x,w,l;
int check(ll mid)
{
ll c=l;
ll g=w;
for(ll i=;i<=x;i++)
{
ll k=(c-a[i].b)/a[i].inc;
ll j=(g-a[i].b)/a[i].inc;
if((c-a[i].b)%a[i].inc!=)
k++;
if((g-a[i].b)%a[i].inc!=)
j++;
if(mid>=k)
{
if(mid>=j)
return ;
else
g-=mid*a[i].inc+a[i].b;
}
}
if(g<=)
return ;
return ;
}
int main()
{
ll i,t;
while(~scanf("%lld%lld%lld",&x,&w,&l))
{
for(ll i=;i<=x;i++)
scanf("%lld%lld",&a[i].b,&a[i].inc);
ll st=;
ll en=1e18;
while(st<en)
{
ll mid=(st+en)>>;
if(check(mid))
en=mid;
else
st=mid+;
}
if(check(st))
printf("%lld\n",st);
else if(check(st-))
printf("%lld\n",st-);
}
return ;
}
 

页面:/ 2

 
 

自动缩放
实际大小
适合页面
适合页宽

50%
75%
100%
125%
150%
200%
300%
400%

 
May Challenge 2016
FORESTGA: Forest Gathering
题目描述
大厨是一个伐木工厂的老板,最近他购买了一个农场,其中有
N
棵树。我们知道每棵树的初
始高度
H
i
和每月这棵树会增长的高度
R
i
。为简单起见,我们假设所有树都是具有相同半径的圆
柱体,因此我们只需关注树的高度。
在大厨所在的国家里,法律不允许将树砍下一部分,因此伐木时必须完整砍下一棵树。同时,
法律也不允许砍下高度小于
L
的树。
这天大厨收到了一个订单,要求提供高度共
W
的木料。大厨想要尽快完成这笔生意,因此他
想知道最少需要等树生长几个月才能完成订单。假设砍树所需的时间可以忽略不计。
输入格式
输入数据的第一行包含三个整数
N
W
L
,分别代表树的棵数、订单要求的树高,以及最
低能砍的树的树高。
接下来
N
行,每行描述一棵树,包含两个整数
H
i
R
i
输出格式
输出一行,包含一个整数,代表大厨最少需要等的月份数。
数据范围和子任务
1
N
10
5
1
W;L
10
18
1
H
i
;R
i
10
9
子任务
1
40
):
1
N;W;L
10
4
子任务
2
60
):
无附加限制
样例数据
输入
3 74 51
2 2
5 7
2 9
输出
7
样例解释
六个月后,各棵树的高度为
14
47
56
,大厨只能砍下第
3
棵树,无法完成订单。
七个月后,各棵树的高度为
16
54
65
,此时可以砍下第
2
和第
3
棵树,可以完成订单了。
1
 
 
May Challenge 2016
时间限制
1
Problem Setter: Maksym Bevza
Problem Tester: Kevin Charles Atienza
Translated by: Hu Zecong
2

CodeChef FORESTGA 二分的更多相关文章

  1. codechef May Challenge 2016 FORESTGA: Forest Gathering 二分

    Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...

  2. CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)

    All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...

  3. [Codechef SSTORY] A Story with Strings - 后缀数组,二分

    [Codechef SSTORY] A Story with Strings Description 给定两个字符串,求它们的最长公共子串.如果解不唯一,输出最先在第二个字符串中出现的那个. Solu ...

  4. 2019.02.15 codechef Favourite Numbers(二分+数位dp+ac自动机)

    传送门 题意: 给444个整数L,R,K,nL,R,K,nL,R,K,n,和nnn个数字串,L,R,K,数字串大小≤1e18,n≤65L,R,K,数字串大小\le1e18,n\le65L,R,K,数字 ...

  5. [JZOJ6089]【CodeChef 2014 April Challenge】Final Battle of Chef【数据结构】【整体二分】

    Description \(n,q,V\leq 100000,w_i\leq 10^9\) Solution 又是一道大数据结构 由于有一个下取整,这就导致了不同时间的修改值是不能简单的直接加在一起的 ...

  6. CodeChef - ELHIDARR Find an element in hidden array(二分交互)

    Find an element in hidden array There is an array of length N consisting of non-negative integers. T ...

  7. CodeChef Forest Gathering —— 二分

    题目链接:https://vjudge.net/problem/CodeChef-FORESTGA 题解: 现场赛.拿到这题很快就知道是二分,但是一直wa,怎么修改也wa,后来又换了种错误的思路,最后 ...

  8. bzoj4408 [Fjoi 2016]神秘数 & bzoj4299 Codechef FRBSUM 主席树+二分+贪心

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4299 https://lydsy.com/JudgeOnline/problem.php?id ...

  9. codechef 两题

    前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...

随机推荐

  1. HTML5标签(语义化)

    HTML语义化是什么? HTML语义化是指根据内容的结构化,选择合适的标签.举个例子:之前所有的都用div, span等标签实现页面结构,而这些标签都没有实际的意义, 而新的HTML5标签<he ...

  2. android studio 运行是,app标题栏不显示

    解决办法:让所有的活动都继承 AppCompatActivity就行了,如: public class FirstActivity extends AppCompatActivity{ ... }

  3. <2014 05 21> 互联网时代的C语言——Go(2)

    **************************************************************************************************** ...

  4. 利用epoll实现异步IO

    之前异步IO一直没搞明白,大致的理解就是在一个大的循环中,有两部分:第一部分是监听事件:第二部分是处理事件(通过添加回调函数的方式).就拿网络通信来说,可以先通过调用 select 模块中的 sele ...

  5. HTTP 错误 500.21 - Internal Server Error 解决方案(转)

    不久前重新安装了Windows7,在安装了VS2010 开发平台之后,将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序“Ni ...

  6. C#生成Windows服务

    1. 新建一个项目,或者从选择当前解决方案--右键-添加--新建项目 2. 选择Visual C#项目-->Windows 服务,填写要创建的服务名称(修改默认的WindowService1成为 ...

  7. Json反序列化Map的key不能是Object

    使用json作为数据传输格式,碰到一个问题.我希望传输的是一个Map<Target, TargetInfo>其中Target是一个对象,作为map的一个key public class T ...

  8. 《深入理解Linux内核》阅读笔记 --- 第四章 中断和异常

    1.中断的作用:中断信号提供了一种方式,使处理器转而去运行正常控制流之外的代码.当一个中断信号到达时,CPU必须停止它当前所做的事,并切换到一个新的活动.为了做到这一点,就要在内核态堆栈保存程序计数器 ...

  9. Django限制请求method

    1.常用的请求method 1.1 GET请求: GET请求一般用来向服务器索取数据,但不会向服务器提交数据,不会对服务器的状态进行更改.比如向服务器获取某篇文章的详情. 1.2 POST请求: PO ...

  10. 【我的Android进阶之旅】 高效的设计稿标注及测量工具Markman介绍

    前言 最近有个烦恼是UI设计师可能太忙了,经常给出的UI设计稿中有很多地方都没有标注,比如长度和颜色值等.这个时候每次都要通过RTX来联系UI设计师或者直接跑到UI设计师面前,喊他重新标注一下,特别影 ...