codeforces 650B - Image Preview

题意:给你n个照片,从第一个照片开始看,如果一张照片是'w',那么要花费b时间去反转他,否则不用反转,看一张从来没看过的照片要1时间, 从一张滑动到另一张要a时间。如果一张照片看过,则不用再反转,也不用再傻1s。求在不超过T时间的前提下最多能看多少张。

思路:首先模拟这个选着过程,这里引入两个指针,lr代表从起点开始从右遍历,ll代表从后遍历到最后一个符合条件的位置,ll到lr之间串如果符合题意则求ans。

注意ll和lr之间一定不超过n。

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 #include <algorithm>
 5 #include <cmath>
 6 #include <cstdlib>
 7 using namespace std;
 8 const double pi=acos(-1);
 9 const int maxn=500010;
10 char str[maxn];
11 int s[2*maxn];//二倍空间:0到n-1是往后遍历,n到2*n-1是往前遍历
12 
13 int main() {
14     int n,a,b,t;
15     while(~scanf("%d%d%d%d",&n,&a,&b,&t)) {
16         scanf("%s",str);
17         int sum=0;
18         for(int i=0; i<n; i++) {
19             if(str[i]=='w')
20                 s[i]=s[i+n]=b+1;
21             else
22                 s[i]=s[i+n]=1;
23             sum+=s[i];
24         }
25         sum-=s[0];
26         int ll=1,lr=n;
27         int ans=0;
28         while(ll<=n&&lr<2*n) {
29             sum+=s[lr++];
30             while(lr-ll>n||sum+(lr-ll-1+min(lr-n-1,n-ll))*a>t) {
31                 sum-=s[ll++];
32             }
33             ans=max(ans,lr-ll);
34         }
35         cout<<ans<<endl;
36     }
37     return 0;
38 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5337529.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值