Codeforces Round #345 D. Image Preview (two points)

Source: Internet
Author: User

Topic links

Test instructions: Look at a picture needs 1 unit time, if it is w need to flip B time, switch to adjacent position (left or right) need a time, ask T time can see a few pictures

From the first start to the right to see a number of pictures and then go to the left will not go to the right, that is, only one time to change direction, many times change the direction of the candle, wasting time. So one enumeration can see the number of pictures N, to the right can see 1 to N, then left to have (n-to the right), and then calculate the time compared to T

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intMax = 5e5 +Ten;6typedefLong LongLL;7 intPri[max];8 CharNum[max];9 intN, a, b, T;Ten BOOLCheckintmid) One { A      for(inti =1; I <= mid; i++) -     { -LL sum1 = Pri[i] + pri[n]-pri[n-(mid-i)];//The total time of the rollover and reading of the position to the right to the left, theLL sum2 = min ((i-1) * A *2+ (mid-i) * A, (I-1) * A + (mid-i) * A *2);//You can switch from the left to the right, or you can switch from the right to the left. -         if(Sum1 + sum2 <=(LL) T) -             return true; -     } +     return false; - } + intMain () A { atscanf"%d%d%d%d", &n, &a, &b, &T); - GetChar (); -scanf"%s", Num +1); -      for(inti =1; I <= N; i++) -Pri[i] = pri[i-1] +1+ (num[i] = ='W'? D |0);//The pri "I" Saves the time it takes to switch from the first image to the one I picture, including rotation and reading -     intL =0, r =N; in      while(L <R) -     { to         intMid = (L + R +1) /2;//without adding a dead loop, r = L + 1 o'clock, +         if(check (mid)) -L =mid; the         Else *R = Mid-1; $     }Panax Notoginsengprintf"%d\n", L); -     return 0; the}
View Code

Codeforces Round #345 D. Image Preview (two points)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.