[2016-03-09][codeforces][651][D][Image Preview]
[2016-03-09][codeforces][651][D][Image Preview]
- 时间:2016-03-09 15:11:14 星期三
- 题目编号:[2016-03-09][codeforces][651][D][Image Preview]
- 题目大意:手机有n章相片,从手机第一张相片开始浏览,浏览一张新相片需要1s,切换相片需要a s,如果相片位置不对,就需要调整相片,需要bs,问T时间内,最多能浏览多少张相片
- 输入:
- n a b t
- 相片的位置信息,w表示横,需要调整,h表示竖的,不需要
- 输出:最大浏览的相片数目
- 分析:仅仅只是往一个方向扫不一定就是最优的方法,可能存在一种情况就是往左扫一段距离,再返回往右扫,浏览的图片更多,
- 方法:统计每个相片消耗的时间(调整+浏览),然后二分最大答案,判断是否能在长度为mid的范围内的tmpt小于等于t
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef long long LL; #define CLR(x,y) memset((x),(y),sizeof((x))) #define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x)) #define FORD(x,y,z) for(int (x)=(y);(x)>=(z);--(x)) #define FOR2(x,y,z) int (x);for((x)=(y);(x)<(z);++(x)) #define FORD2(x,y,z) int (x);for((x)=(y);(x)>=(z);--(x)) const int maxn = 5 * 1E5 + 100; char str[maxn]; int tol[maxn],n,a,b,t; int check(int x){ if(tol[x] + (x-1)*a <= t) return 1; FOR(i,1,x){ int tmp=tol[i]+(tol[n]-tol[n-(x-i)])+min((i-1)*2+(x-i),(x-i)*2+(i-1))*a; if(tmp <= t) return 1; } return 0; } int main(){ scanf("%d%d%d%d%s",&n,&a,&b,&t,str+1); FOR(i,1,n+1){ tol[i] = tol[i- 1] + 1 + (str[i] == 'w'?b:0); } int l = 0,r = n ,mid; while(r - l > 1){ mid = l + ((r - l + 1)>>1); if(check(mid)) l = mid; else r = mid; } printf("%d\n",check(r)?r:l); return 0; } |
浙公网安备 33010602011771号