Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分
D. Image Preview
题目连接:
http://www.codeforces.com/contest/651/problem/D
Description
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a seconds to swipe from photo to adjacent.
For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can't be rotated. It takes b second to change orientation of the photo.
Vasya has T seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends b seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn't spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.
Help Vasya find the maximum number of photos he is able to watch during T seconds.
Input
The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·105, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.
Second line of the input contains a string of length n containing symbols 'w' and 'h'.
If the i-th position of a string contains 'w', then the photo i should be seen in the horizontal orientation.
If the i-th position of a string contains 'h', then the photo i should be seen in vertical orientation.
Output
Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds.
Sample Input
4 2 3 10
wwhw
Sample Output
2
Hint
题意
有n张照片,你看一张照片需要1秒,你滑动照片到左边或者右边,需要a秒,翻转照片需要b秒,问你在T秒内最多看多少张照片
照片必须看,不能跳过。
手机是h的,一直保持着h不变。
题解:
暴力枚举左边看多少张,然后二分右边最多看多少张
暴力枚举右边看多少张,然后二分左边。
具体实现,就当成模拟题去做吧……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+7;
int n,a,b,T;
string s;
int d[maxn],d2[maxn];
int check(char k)
{
if(k=='w')return 0;
else return 1;
}
int update(int x,int y)
{
if(x+y>1e9)return 1e9+1;
return x+y;
}
int main()
{
scanf("%d%d%d%d",&n,&a,&b,&T);
T+=a;
cin>>s;
int now = 1;
for(int i=0;i<n;i++)
{
if(i!=0)d[i]=d[i-1];
if(check(s[i])!=now)
d[i]=update(d[i],a+b+1);
else
d[i]=update(d[i],a+1);
}
now = 1;
reverse(s.begin(),s.end());
for(int i=0;i<n;i++)
{
if(i!=0)d2[i]=d2[i-1];
if(check(s[i])!=now)
d2[i]=update(d2[i],a+b+1);
else
d2[i]=update(d2[i],a+1);
}
reverse(s.begin(),s.end());
int ans = 0;
for(int i=0;i<n;i++)
{
if(T<d[i])break;
int las = T - d[i];
ans=max(i+1,ans);
if(i==n-1)continue;
if(las<a*i+d2[0])continue;
las-=a*i;
int l=0,r=n-i-2,Ans=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(d2[mid]<=las)l=mid+1,Ans=mid;
else r=mid-1;
}
ans=max(i+1+Ans+1,ans);
}
if(s[n-1]!=s[0])T-=b;
for(int i=0;i<n-1;i++)
{
if(T<d2[i]+d[0]+a)break;
int las = T - d2[i] - d[0] - a;
ans=max(i+2,ans);
if(las<a*i)continue;
las-=a*i;
las+=d[0];
int l=0,r=n-i-2,Ans=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(d[mid]<=las)l=mid+1,Ans=mid;
else r=mid-1;
}
ans=max(i+1+Ans+1,ans);
}
cout<<ans<<endl;
}
Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分的更多相关文章
- Codeforces Round #345 (Div. 1) B. Image Preview
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- Codeforces Round #367 (Div. 2) A B C 暴力 二分 dp(字符串的反转)
A. Beru-taxi time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #354 (Div. 2) C. Vasya and String 二分
C. Vasya and String 题目连接: http://www.codeforces.com/contest/676/problem/C Description High school st ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
随机推荐
- MFC单文档框架分析及执行流程(转)
原文转自 https://blog.csdn.net/u011619422/article/details/40402705 首先来分析一下MFC单文档类的结构: 它包括如下几个类: CAboutDl ...
- 【bzoj3545】peaks
离线一下,动态开点+线段树合并,然后权值线段树上询问kth即可. #include<bits/stdc++.h> ; *; using namespace std; ; inline in ...
- C后端设计开发 - 第4章-武技-常见轮子下三路
正文 第4章-武技-常见轮子下三路 后记 如果有错误, 欢迎指正. 有好的补充, 和疑问欢迎交流, 一块提高. 在此谢谢大家了. Moonlight Shadow 纪念那个我爱的, 被我感动的女孩 ...
- Leetcode 之Binary Tree Postorder Traversal(47)
中序遍历二叉搜索树,得到的是一个有序的结果,找出其中逆序的地方就可以了.如果逆序的地方相邻,只需把逆序的相换即可:如果不相邻,则需要找到第二个逆序对的 第二个元素再做交换. 定义两个指针p和q来指定需 ...
- LeetCode解题报告—— Container With Most Water & 3Sum Closest & Letter Combinations of a Phone Number
1. Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a ...
- Simplify Path——简单经典的预处理
Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...
- 魔法上网之Ubuntu部署“酸酸”
“酸酸”,即s*h*a*d*o*w*s*o*c*k*s,用于魔法上网,用python写成. 在ubuntu环境下,用pip包管理工具可以非常方便地安装“酸酸”服务:ssserver. 先安装pip(假 ...
- 在C#中使用正则表达式筛选出图片URL并下载图片URL中的图片到本地
本功能主要用到的知识点如下: 1.正则表达式 2.C#中下载文件功能的实现 3.泛型集合的使用 4.进程的简单操作(用于结束当前程序) 下面就简单说一下是如何使用这些知识点的.先详细说下这个程序主要实 ...
- 学习LoadRunner之C语言函数
学习LoadRunner之C语言函数 Action() { /*strchr和strrchr的区别*/ /* char *strTest1="citms citms"; char ...
- 【初探移动前端开发04】jQuery Mobile 一
网格布局 jquery mobile提供一种多列布局功能,由于移动设备的屏幕大小原因,一般情况还是不要使用多列布局啦. jquery mobile提供一种css样式规则来定义多列布局,对应css为ui ...