zoukankan      html  css  js  c++  java
  • codeforces 650B

    题意:给你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
  • 相关阅读:
    RabbitMQ的ACK机制
    Flex保存文件 FileReference.save(data,filename)
    Flex Builder cannot locate the required debugger version of Flash Player
    Flex每日小记
    IT民工
    R读取文件内容到Frame
    ArcGIS9.2 9.3
    超时空的心情
    ArcMap中设置.mxd相对路径
    MyEclipse Flex Tomcat BlazeDS
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5337529.html
Copyright © 2011-2022 走看看