题意:

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

分析:

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

代码:

#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. h5学习-webstorm工具的激活

    这里有个快速激活webstorm的方法:http://jingyan.baidu.com/article/9f63fb919674f2c8400f0e9a.html h5的轮廓工具:https://g ...

  2. jquery + ajax 实现多条件查询

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="JquerySort.aspx. ...

  3. 使用Dotfuscator保护.NET DLL加密DLL,防止DLL反编译

    1.下载地址 https://pan.baidu.com/s/1ztWlBxw1Qf462AE7hQJQRg 2.操作步骤 2.1安装后打开DotfuscatorPro软件,如下图所示: 2.2 选择 ...

  4. mysql 判断null 和 空字符串

    1.在mysql中null 不能使用任何运算符与其他字段或者变量(函数.存储过程)进行运算.若使用运算数据就可能会有问题. 2.对null 的判断: 创建一个user表:id 主健 name 可以为空 ...

  5. iOS Programming NSUserDefaults

    iOS Programming NSUserDefaults  When you start an app for the first time, it uses its factory settin ...

  6. Node.js——环境变量

  7. ES6特性的两点分析

    块级作用域声明let.constES6中const 和let的功能,转换为ES5之后,我们会发现实质就是在块级作用改变一下变量名,使之与外层不同.ES6转换前: let a1 = 1; let a2 ...

  8. sql server 强制关闭连接

    USE master; GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) FROM ma ...

  9. 不能局部安装webpack的解决方法

    npm ERR! code ENOSELFnpm ERR! Refusing to install package with name "webpack" under a pack ...

  10. vue相关技术

    vuejs2.0:渐进式JavaScript框架,易用.灵活.高效,似乎任何规模的应用都适用. element:基于vuejs2.0的ui组件库. vue-router:一般单页面应用spa都要用到的 ...