【1】【二分搜索】CodeForces 650B Image Preview
2016-08-10 21:20
501 查看
B. Image Preview
time limit per test:1 secondmemory limit per test:256 megabytes
input:standard input
output:standard output
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.
Examples
input
4 2 3 10
wwhw
output
2
input
5 2 4 13
hhwhh
output
4
input
5 2 4 1000
hhwhh
output
5
input
3 1 100 10
whw
output
0
Note
In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.
Note that in the last sample test the time is not enough even to watch the first photo, also you can’t skip it.
链接
CodeForces 650B
题意
在手机里面左右翻照片。手机是固定的,w表示照片要旋转,用时b秒,h表示不用转。关键是第一张往右滑就是最后一张,最后一张往左滑就是第一张。每张新照片要看1秒钟,看过的照片不会再看,即不会在花费1秒。照片滑动到相邻的一张要a秒,问T时间内最多可以看几张。
分析
16/8/10由于本来没读懂上面加粗的部分,所以不知道这道题有最优情况。看了网上的题解有两种代码实现方法,我目前学了扩大数组的那种。l和r分别表示往左看到哪一张和往右看到哪一张,过程中还有一些细节也要注意。
相关文章推荐
- Codeforces 782B 二分搜索
- CodeForces - 287B Pipeline 二分搜索
- CodeForces - 924B Three-level Laser (二分搜索)
- Codeforces 887E Little Brothers 过两点的圆和给定的圆的关系 二分搜索
- CodeForces-768B Code for 1 二分搜索线段
- codeforces 776C Molly's Chemicals(前缀和 二分搜索)
- codeforces 778D. String Game (二分搜索)
- CodeForces 371C-Hamburgers(二分搜索)
- Codeforces 671B Robin Hood (二分搜索)
- CodeForces 716B Complete The Graph(二分搜索)(最短路)
- codeforces 785 C. Anton and Fairy Tale (数学 二分搜索)
- 【1】【二分搜索】CodeForces 492D Vanya and Computer Game
- codeforces 932D Tree 倍增法+二分搜索
- codeforces 895B. XK Segments (二分搜索)
- Codeforces-231C-To Add or Not to Add(二分搜索)
- Codeforces 484B. Maximum Value(高效二分搜索)
- codeforces 732D Exams 二分搜索 贪心
- codeforces 289B - Polo the Penguin and Matrix 二分+dp
- 二分搜索应用(旋转数组)——C语言
- 二分搜索的拓展用法