Codeforces 651D Image Preview【二分+枚举】
题意:
若干张照片,从头开始可以向左右两边读,已经读过的不需要再读,有的照片需要翻转,给定读、滑动和翻转消耗的时间,求在给定时间内最多能读多少页?
分析:
首先明确,只横跨一次,即先一直读一边然后再一直读另一边,这样消耗的滑动时间最少。是否能在给定时间内读完页数很好判断,所以用二分+枚举,先枚举左边的所有可能情况,再二分右边求出最大页数, 再枚举右边,求出左边。取两边的最大值即可。
代码:
#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【二分+枚举】的更多相关文章
- Codeforces 807C - Success Rate(二分枚举)
题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...
- Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))
题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...
- codeforces 650B . Image Preview 二分
题目链接 B. Image Preview time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces J. Sagheer and Nubian Market(二分枚举)
题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces 660C - Hard Process - [二分+DP]
题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...
- Codeforces - 773A - Success Rate - 二分 - 简单数论
https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- FZU-2216 The Longest Straight (二分枚举)
题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...
- uva 12587 二分枚举
思路:维护一个森林,二分枚举最小的最大值. #include<set> #include<map> #include<cmath> #include<queu ...
随机推荐
- XmlDocument
XmlDocument增删改查. using System; using System.Collections.Generic; using System.ComponentModel; using ...
- EL表达式、JSTL
EL表达式 一.简介 > JSP表达式 <%= %> 用于向页面中输出一个对象. > 到JSP2.0时,在我们的页面中不允许出现 JSP表达式和 脚本片段. ...
- iOS Programming Controlling Animations 动画
iOS Programming Controlling Animations 动画 The word "animation" is derived from a Latin wor ...
- 分析HTTP 2.0与HTTP 1.1区别
1.什么是HTTP 2.0 HTTP/2(超文本传输协议第2版,最初命名为HTTP 2.0),是HTTP协议的的第二个主要版本,使用于万维网.HTTP/2是HTTP协议自1999年HTTP 1.1发布 ...
- Java之抽象和封装
① 如何从现实世界中抽象出类? 根据软件开发需求: 发现类-->发现类的属性-->发现类的方法 ② 构造方法的作用和特点是什么? 作用:在创建对象时执行一些初始化操作 ...
- 中国版 Office 365 (X-Tenant / Tango) 功能验证报告 - 2 基本步骤
说明: 1. 前期准备 - 在Azure上模拟出生产环境: 包括父域域控.子域域控.父域的Exchange Server.子域的Exchange Server.对Exchange Server, 需要 ...
- http 1.0 http 1.1 http 2.0的区别
HTTP/1.0 版的主要缺点是,每个TCP连接只能发送一个请求.发送数据完毕,连接就关闭,如果还要请求其他资源,就必须再新建一个连接. http1.1优点: 1.HTTP 1.1 版引入了持久连接( ...
- vue脚手架引入swiper
方法一: 下载swiper: npm install swiper --save-dev swiper4.0使用入口:http://www.swiper.com.cn/usage/index.html ...
- LCS以及输出路径模板
记忆 两个for用来寻找LCS,DP是二维的,每一维代表了字符串的长度. 寻找的代码部分 if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][ ...
- [BZOJ] 1037 [ZJOI2008]生日聚会
Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3007 Solved: 1795 [Submit][Status][Discuss] Descript ...