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)