Codeforces650B Image Preview
来源:互联网 发布:查看店铺数据的插件 编辑:程序博客网 时间:2024/06/02 18:04
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 photo1. 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 andcan'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 spends1 second to notice all details in it. If photo is in the wrong orientation, he spendsb 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.
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 photoi should be seen in the horizontal orientation.
If the i-th position of a string contains 'h', then the photoi should be seen in vertical orientation.
Output the only integer, the maximum number of photos Vasya is able to watch during thoseT seconds.
4 2 3 10wwhw
2
5 2 4 13hhwhh
4
5 2 4 1000hhwhh
5
3 1 100 10whw
0
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.
题意:Vasya从第一张照片开始看,可以向左翻或者向右,第1张左边是第n张,第n张右边是第一张,翻一次要a时间,照片有'w'和'h'两种摆放,‘w’的照片要耗费b时间翻转,看一张照片要1时间,一共有T时间,问最多可以看多少张照片?
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define ll long long int#define maxn 500005int sum[2*maxn];char s[maxn];int main(){ int n, a, b, T, i, h, r, ans, ss; scanf("%d %d %d %d", &n, &a, &b, &T); scanf("%s", s); ss = 0; for(i = 0;i < n;i++){ if(s[i] == 'w') sum[i] = sum[i+n] = b + 1; else sum[i] = sum[i+n] = 1; ss += sum[i]; } ss -= sum[0]; h = 1, r = n, ans = 0; while(h<=n&&r<2*n){ ss += sum[r++]; // 维持n以内||先右后左 先左后右 while(r-h>n||ss+(r-h-1+min(r-n-1, n-h))*a>T){ ss -= sum[h++]; } ans = max(ans, r-h); } printf("%d\n", ans);}
- Codeforces650B Image Preview
- 【Codeforces650B】Image Preview【Two-Pointers】
- Local image preview sample
- Image Upload Preview(转)
- #345 Div2 D. Image Preview
- html5 file api to preview image
- Codeforces 651D:Image Preview 二分
- Codeforces 650B Image Preview 【二分】
- Codeforces #345 div1 B. Image Preview 二分
- Codeforces 651D Image Preview【二分+枚举】
- cf#345-D - Image Preview-二分
- 二分 - CF 650B Image Preview
- 【20.35%】【codeforces 651D】Image Preview
- CodeForces 650 B.Image Preview(二分)
- preview
- preview
- Preview
- jquery input file show image preview 预览图片
- java异常处理
- Java day02 for循环练习 带星图案
- BestCoder Round #75 1002模拟
- 【hdu2899】Strange fuction——三分
- HttpClient设置编码类型
- Codeforces650B Image Preview
- 家用路由器性能指标
- CALayer图片淡入淡出效果
- JVM字节码
- html5 FileReader
- 记《第一行代码》读后感---Service服务
- 闭关日记 Day01
- 随堂笔记160302OOP和String
- 向下转型