CodeChef FORESTGA 二分
Forest GatheringProblem code: FORESTGA
|
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian 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 N, W 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 ≤ W, L ≤ 1018
- 1 ≤ Hi, Ri ≤ 109
Subtasks
- Subtask #1 [40 points]: 1 ≤ N, W, L ≤ 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 14, 47 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 16, 54 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%
CodeChef FORESTGA 二分的更多相关文章
- codechef May Challenge 2016 FORESTGA: Forest Gathering 二分
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)
All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...
- [Codechef SSTORY] A Story with Strings - 后缀数组,二分
[Codechef SSTORY] A Story with Strings Description 给定两个字符串,求它们的最长公共子串.如果解不唯一,输出最先在第二个字符串中出现的那个. Solu ...
- 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,数字 ...
- [JZOJ6089]【CodeChef 2014 April Challenge】Final Battle of Chef【数据结构】【整体二分】
Description \(n,q,V\leq 100000,w_i\leq 10^9\) Solution 又是一道大数据结构 由于有一个下取整,这就导致了不同时间的修改值是不能简单的直接加在一起的 ...
- 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 ...
- CodeChef Forest Gathering —— 二分
题目链接:https://vjudge.net/problem/CodeChef-FORESTGA 题解: 现场赛.拿到这题很快就知道是二分,但是一直wa,怎么修改也wa,后来又换了种错误的思路,最后 ...
- bzoj4408 [Fjoi 2016]神秘数 & bzoj4299 Codechef FRBSUM 主席树+二分+贪心
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4299 https://lydsy.com/JudgeOnline/problem.php?id ...
- codechef 两题
前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...
随机推荐
- 学习使用turtlebot2——安装ROS Indigo系统
最近在学习使用turtlebot2,特此做一些学习记录. 安装ROS前要先决定自己电脑的Ubuntu(乌班图)系统.现在学习ROS常使用的Ubuntu系统有Ubuntu 16.04 和Ubuntu14 ...
- 巨蟒python全栈开发-第6天 is&==
1.小数据池 2.id 3.decode和encode 小数据池 #小数据池:不要死磕就行#python为了简化,搞出来的一个东西 ID (1)# id()函数可以帮我们查看一个变量的内存地址# a= ...
- Subscription
- tableView的使用(一)
//tableView的创建 //1.初始化 initWithFrame:style:(plian,gronp) //2.设置属性(行高, 分割线, 表头, 表尾) //3.添加到父 ...
- 视频流协议HLS与RTMP 直播原理 点播原理
小结: 1.HLS原理 视频--->图像.声音分别编码打包切割容器文件ts,建立纯文本索引文件.m3u8--->播放器http下载容器文件.索引文件,播放,下载 基于HLS可以实现直播和点 ...
- Date、Calendar、Timestamp的区别与转换
1.Java.util.Date 包含年.月.日.时.分.秒信息. // String转换为Date String dateStr="2013-8-13 23:23:23"; St ...
- 【MonogDB】The description of index(二) Embedded and document Index
In this blog, we will talk about another the index which was called "The embedded ". First ...
- C++对象模型那点事儿(布局篇)
1 前言 在C++中类的数据成员有两种:static和nonstatic.类的函数成员由三种:static,nonstatic和virtual. 上篇我们尽量说一些宏观上的东西,数据成员与函数成员在类 ...
- 最全的sublime插件整理
Package Control 插件管理器 1)在Sublime中打开View –> Show Console,将以下代码复制到输入框中后按回车键 import urllib.request,o ...
- APP数据埋点分类方式
1.数据埋点的重要性 在现实工作中,数据的整体流程为:数据生产-数据采集-数据处理-数据分析和挖掘-数据可视化,其中,数据采集是很重要的一个环节,数据采集得全不全.对不对,直接决定数据广度和质 ...