CodeChef Forest Gathering —— 二分
题目链接:https://vjudge.net/problem/CodeChef-FORESTGA
题解:
现场赛。拿到这题很快就知道是二分,但是一直wa,怎么修改也wa,后来又换了种错误的思路,最后还是觉得二分是正确的,但还是wa。人生,就是在这些瞬间被怀疑的……
结束后,才发现,test()的时候溢出了。应该把判断放在循环里面,如果达到要求的,就立刻返回。因为达到要求后,后面的运算都是多余的。
反思:
在某些判断中,如果达到要求后,就立刻执行。不要等所有操作完成后,再执行,因为可能出现意想不到的结果。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
//#define LOCAL
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 1e5+;
const double pi = acos(-1.0); LL n,w, li;
int h[maxn], r[maxn]; bool test(LL m)
{
LL s = ;
for(int i = ; i<=n; i++)
{
LL t = 1LL*h[i]+1LL*m*r[i];
if(t<li) continue;
s += t;
if(s>=w)
return ;
}
return ;
} //bool test(LL m)
//{
// LL s = 0;
// for(int i = 1; i<=n; i++)
// {
// LL t = 1LL*h[i]+1LL*m*r[i];
// if(t<li) continue;
// s += t;
// }
// return s>=w; //加完再判断会溢出。
//} int main()
{
scanf("%lld%lld%lld",&n,&w,&li);
for(int i = ; i<=n; i++)
scanf("%d%d",&h[i],&r[i]); LL l = , r = 1e18;
while(l<r)
{
LL m = (l+r)>>;
if(test(m))
r = m;
else
l = m + ;
}
printf("%lld\n",r);
}
CodeChef Forest Gathering —— 二分的更多相关文章
- codechef May Challenge 2016 FORESTGA: Forest Gathering 二分
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】
链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- CodeChef FORESTGA 二分
Forest Gathering Problem code: FORESTGA Tweet ALL SUBMISSIONS All submissions for this problem ...
- CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)
All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) E. Arson In Berland Forest 二分 前缀和
E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every ce ...
- [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 ...
随机推荐
- ES6之Array.includes()函数
一.定义 includes() 方法用来判断一个数组是否包含一个指定的值,如果是返回 true,否则false. 二.语法 arr.includes(searchElement) arr.includ ...
- CF768
Codeforces Round #406 (Div. 1) A.Berzerk 考虑先手必胜态,一定是先手移动到某一个位置以后,这个位置是后手的必败态 考虑先手必败态,一定是无论先手如何移动,先手所 ...
- Wish3D用户必看!模型加载失败原因汇总
上传到Wish3D的模型加载不出来,作品显示页面漆黑一片,是什么原因? 很有可能是操作过程中的小失误,不妨从以下几点检查.还是不行的请加QQ群(Wish3D交流群3):635725654,@Wish3 ...
- 第四讲_图像识别之图像分类Image Classification
第四讲_图像识别之图像分类Image Classification 目录 图片分类 性能指标:top1,top5 ILSVRC:每种任务数据集不一样 imageNet:根据WorldNet组织的图片集 ...
- 百科知识 scm文件如何打开
用scplayer打开,目前有效的下载链接将是: http://download.csdn.net/download/kevingao/2686778
- Hibernate中的条件查询完毕类
Hibernate中的条件查询有下面三个类完毕: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类
- HDU1532_Drainage Ditches(网络流/EK模板/Dinic模板(邻接矩阵/前向星))
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Triangle 三角形——找出三角形中从上至下和最小的路
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- 笔记03 wpf 在MVVM模式下怎样在Viewmodel里面获得view的控件对象
转自http://blog.csdn.net/qing2005/article/details/6601199http://blog.csdn.net/qing2005/article/detail ...
- paxos算法之粗浅理解
paxos出身 paxos出身名门,它爹是没多久前获得图灵奖的在分布式领域大名鼎鼎的LeslieLamport. paxos为何而生 那么Lamport他老人家为什么要搞这个东东呢,不是吃饱了撑的,而 ...