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 ...
随机推荐
- java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to
在做android解析服务器传来的json时遇到的错误. 服务器传来的数据格式 [{"," id":"7ef6815938394fce88a5873312b66 ...
- Bmob使用心得
1.在 Project 的 build.gradle 文件中添加 Bmob的maven仓库地址,示例如下:(注意文字说明部分): allprojects { repositories { jcente ...
- 迅为电子4.3寸CAN总线工业平板电脑简介
型号:iTOP-HMI043-C 4.3寸CAN总线工业平板电脑支持CAN通讯显示器,显示:显示尺寸:4.3英寸:分辨率:480×272 TFT液晶 65536色 :接口:支持CAN 2.0B:USB ...
- python练习1 登录和三级菜单
,: username1 = input("请输入您的用户名:")# password1 = getpass.getpass("请输入您的密码:") passw ...
- vue工程化之去除Eslint验证
有的时候用vue-cli创建好项目之后,写代码时会出现换行和空格报错,出现这么写错误是什么原因呢? 相信第一次接触时有点摸不着头脑.其实是在你用vue-cli脚手架构建项目时用了ESLint代码检查工 ...
- 01XML文档结构
文档结构 2.1文档结构 2.1.1文档声明及字符编码 <?xml version=“1.0” encoding=“”gb2312 standalone=“yes”?> <? 告诉 ...
- 模板—trie图
做了某题之后发现trie的AC自动机太垃圾了,动不动就TLE,然后我就去学了trie图. #include<iostream> #include<cstdio> using n ...
- filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration interface"
filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration inter ...
- html页面比较长,如何用js实现网页一打开显示在网页的中部?
加入js代码 <style type="text/css"> body { height: 2000px; } </style> <script ty ...
- 题解 洛谷P4035/BZOJ1013【[JSOI2008]球形空间产生器】
题目链接在这QvQ "你要求出这个n维球体的球心坐标",这使我想到的解方程...... 先假设n=2,这是一个二维平面.设圆心的坐标为\((x,y)\),有两个坐标\((a_1,b ...