题意:

若干张照片,从头开始可以向左右两边读,已经读过的不需要再读,有的照片需要翻转,给定读、滑动和翻转消耗的时间,求在给定时间内最多能读多少页?

分析:

首先明确,只横跨一次,即先一直读一边然后再一直读另一边,这样消耗的滑动时间最少。是否能在给定时间内读完页数很好判断,所以用二分+枚举,先枚举左边的所有可能情况,再二分右边求出最大页数, 再枚举右边,求出左边。取两边的最大值即可。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 500005, INF = 0x3f3f3f3f;
int ta, tb, n, T;
ll t[maxn], t1[maxn];
int main (void)
{
cin>>n>>ta>>tb>>T;
string s;
char a; cin>>a;
if(a=='w') T-=tb;
T--;
if(T<0){
cout<<0<<endl;
return 0;
}
cin>>s;
for(int i = 0; i < n - 1; i++){
t[i] = t[i -1] + 1 + ta;
if(s[i] == 'w') t[i] += tb;
}
reverse(s.begin(), s.end());
for(int i = 0; i < n - 1; i++){
t1[i] = t1[i -1] + 1 +ta;
if(s[i] == 'w') t1[i] += tb;
}
int res = 0;
for(int i = 0; i < n; i++){
if(t1[i - 1] > T) break;
int l = 0, r = n - i ;
while(l < r - 1){
int mid = (l + r)/2;
if(mid > 0 && t1[i - 1]+ t[mid - 1] + i * ta <= T) l = mid;
else r = mid;
}
res = max(res, l + i);
} for(int i = 0; i < n; i++){
if(t[i - 1] > T) break;
int l = 0, r = n - i;
while(l < r - 1){
int mid = (l + r)/2;
if(mid > 0 && t[i - 1]+ t1[mid - 1] + i * ta <= T) l = mid;
else r = mid;
}
res = max(res, l + i);
} cout<<res + 1<<endl;
return 0;
}

Codeforces 651D Image Preview【二分+枚举】的更多相关文章

  1. Codeforces 807C - Success Rate(二分枚举)

    题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...

  2. Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))

    题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...

  3. codeforces 650B . Image Preview 二分

    题目链接 B. Image Preview time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Codeforces J. Sagheer and Nubian Market(二分枚举)

    题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...

  5. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  6. Codeforces - 773A - Success Rate - 二分 - 简单数论

    https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...

  7. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  8. FZU-2216 The Longest Straight (二分枚举)

    题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...

  9. uva 12587 二分枚举

    思路:维护一个森林,二分枚举最小的最大值. #include<set> #include<map> #include<cmath> #include<queu ...

随机推荐

  1. 构建微服务开发环境5————安装Node.js

    [内容指引] 下载Node.js: Mac下安装Node.js: Windows下安装Node.js; 查看node和npm的版本. 一.下载Node.js 访问Node.js官网:https://n ...

  2. php(一)

    PHP (Hypertext preprocessor 超文本预处理器) 1.环境工具 Xampp等工具 2.apache配置 默认的Apache路径是  c:/xampp/apache 文件夹 可以 ...

  3. struts2 源码地址

    http://archive.apache.org/dist/struts/

  4. 修改vim注释字体颜色

    vim /etc/vimrc#最后一行新增代码块hi comment ctermfg=6 注:注释用 " 标注 PS:默认的注释颜色是4  然后有0,1,2,3,4,5,6,7来选择.可以除 ...

  5. windows ubuntu bcdeditor

    双系统. 先装windows,后装ubuntu12.04 为了避免grub引导,所以安装bcdeditor. 平时使用没有什么不适,可是每次linux升级内核以后,grub列表可能就会消失,自然是不能 ...

  6. 深入理解java虚拟机---垃圾收集器和分配策略-1

    博文重点: 学习目标:哪些内存需要回收 什么时候回收    如何回收 在基于概念讨论的模型中,主要对Java堆和方法区进行讨论. why?:一个接口中的多个实现类需要的内存可能不一样,一个方法中的多个 ...

  7. Mybatis输入输出映射_动态sql_关联关系(一对一、一对多、多对多)

    Mybatis输入输出映射_动态sql_关联关系(一对一.一对多.多对多)输入输出映射parameterType完成输入映射parameterType可以传入的参数有,基本数据类型(根据id查询用户的 ...

  8. css + 和 ~的区别

    <style type="text/css"> h1 + p { margin-top:50px; color:red; } </style> <p& ...

  9. MSYS2 使用

    在Windows下编译mongo-c-driver 1.3.x 在Windows下编译mongo-c-driver 1.3.x 1.安装 MSYS2https://sourceforge.net/pr ...

  10. Quartz任务调度2

    注意: 不同的版本的jar包,具体的操作不太相同,但是思路是相同的:比如1.8.6jar包中,JobDetail是个类,直接通过构造方法与Job类关联.SimpleTrigger和CornTrigge ...