codeforces #262 DIV2 C称号Present(二分法+贪婪)
职务地址:http://codeforces.com/contest/460/problem/C
这个题是用二分枚举最小值。然后推断是否能在规定的次数内使得全部的数都达到这个值。推断的时候要用贪心的方法推断,从左往右遍历。这时候须要让每次浇花的范围尽量向右。所以当到达一个不得不浇花的地方时,要继续占用所须要的浇花次数。当浇花次数不够用的时候,就说明无法达到。
在我的代码中,c数组是记录当前到了该点的时候浇花范围的最右界。表示到了这个地方的时候少了多少次覆盖。y就代表当前这个数被多少个浇花范围覆盖。x是指还剩余的浇花次数。
忘了初始化。。二分非常明显不好调试。
。调了将近20分钟才发现忘了对C数组初始化。。
。sad。
。。。
代码例如以下:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <queue>
using namespace std;
#define LL __int64
LL a[110000], b[110000], c[110000];
int main()
{
LL n, m, i, w, ans, x, y;
scanf("%I64d%I64d%I64d",&n,&m,&w);
for(i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
}
memset(c,0,sizeof(c));
LL low=1, high=1e10, mid;
while(low<=high)
{
mid=(high+low)/2;
//printf("%I64d\n",mid);
x=m;
y=0;
memset(c,0,sizeof(c));
int flag=0;
for(i=0;i<n;i++)
{
b[i]=mid-a[i];
if(b[i]<0)
b[i]=0;
}
for(i=0;i<n;i++)
{
y+=c[i];
b[i]-=y;
if(b[i]>0)
{
if(x-b[i]<0)
{
flag=1;
break;
}
else
{
x-=b[i];
y+=b[i];
if(i+w<n)
c[i+w]-=b[i];
}
}
}
//printf("%I64d %d\n",mid, flag);
if(flag)
{
high=mid-1;
}
else
{
ans=mid;
low=mid+1;
}
//printf("%I64d\n",ans);
}
printf("%I64d\n",ans);
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
codeforces #262 DIV2 C称号Present(二分法+贪婪)的更多相关文章
- codeforces #262 DIV2 B题 Little Dima and Equation
题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
随机推荐
- hdu 1290 竭诚为杭州电礼物50周年
专门为杭州电50周年礼事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- [SignalR]初步认识以及安装
原文:[SignalR]初步认识以及安装 1.什么是ASP.NET SignalR? ASP .NET SignalR是一个 ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时 ...
- CentOS7 安装Hadoop集群环境
先按照上一篇安装与配置好CentOS以及zookeeper http://www.cnblogs.com/dopeter/p/4609276.html 本章介绍在CentOS搭建Hadoop集群环境 ...
- Ruby: Count unique elements and their occurences in an array
Is there a method in Ruby that takes an array, and counts all unique elements and their occurrences ...
- NSString 筛选和最后一个空白、空行,多换行成一个新行
- (NSString *)filterBlankAndBlankLines:(NSString *)str { NSMutableString *Mstr = [NSMutableString st ...
- 鸟哥的私房菜上 xpenguins 设备(ubuntu 12.04)
看了一个暑假linux,我觉得很辛苦啊,要很好地利用linux并不是的easy... 今天装了一下鸟哥课后给的xpenguins软件,就是桌面特性软件.会有非常多企鹅下落,本以为能够非常轻松的搞定.没 ...
- 用Fine Uploader+ASP.NET MVC实现ajax文件上传[代码示例]
Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件的 Javascript 组件. This project attempts to achi ...
- 【转】monkey工具简介
原文地址:http://www.testwo.com/blog/6188 一.Monkey 简介 Android的SDK 里面,Monkey的tools是一个命令行工具,当连接Android设备时 ...
- java_ java多线程返回函数结果
两种方式:一种继承Thread类实现:一种通过实现Callable接口. 第一种方法: 因为实现Thread类的run方法自身是没有返回值的,所以不能直接获得线程的执行结果,但是可以通过在run方法里 ...
- java io流之int数组数据的插入与取出
java io流大家都非常熟悉吧,有时候假设用的不熟,对于数据的处理真的非常头疼,以下是对与int数组的处理. 以下是代码: public class Stream { private int a[] ...