Codeforces Round #345 D. Image Preview(二分)
题意:看一个图片需要1单位时间,如果是 w 需要翻转 b 时间,切换到相邻位置(往左或者往右)需要 a 时间,求T时间最多能看几张图片
从第一个开始向右走看若干个图片然后往如果往左走就不会再往右走了,也就是只能一次改变方向,多次改变方向就得不偿失了,浪费时间。所以一次枚举能看图片的数量n,往右能看1到n个,那么往左就有 (n - 往右的)个,然后算出时间跟T相比
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int Max = 5e5 + ;
typedef long long LL;
int pri[Max];
char num[Max];
int n, a, b, T;
bool check(int mid)
{
for (int i = ; i <= mid; i++)
{
LL sum1 = pri[i] + pri[n] - pri[n - (mid - i)]; // 往右 往左 到达的位置 的 翻转和阅读总时间,
LL sum2 = min((i - ) * a * + (mid - i) * a, (i - ) * a + (mid - i) * a * ); // 可以从 左边 切换到右边,也可以从右边切换到左边
if (sum1 + sum2 <= (LL)T)
return true;
}
return false;
}
int main()
{
scanf("%d%d%d%d", &n, &a, &b, &T);
getchar();
scanf("%s", num + );
for (int i = ; i <= n; i++)
pri[i] = pri[i - ] + + (num[i] == 'w' ? b : ); //pri【i】存的是从第一张切换到看第 i 张图片所需要的时间,包括旋转和阅读
int l = , r = n;
while (l < r)
{
int mid = (l + r + ) / ; // 不加一会死循环, r = l + 1时,
if (check(mid))
l = mid;
else
r = mid - ;
}
printf("%d\n", l);
return ;
}
Codeforces Round #345 D. Image Preview(二分)的更多相关文章
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分
D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...
- Codeforces Round #345 (Div. 1) B. Image Preview
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
随机推荐
- 论文笔记Outline
1.Information publication: author: 2.What 3.Dataset 4.How input: output: method: 5.Evaluation: basel ...
- ipython又一方便的调试和应用工具!!!
控制台下://ipython 命令丰富 比如:ls 显示目录 ipython --pylab %run -p *.py quit关闭 示例: In []: %run -p test.py H ...
- 十天冲刺---Day2
站立式会议 站立式会议内容总结: git上Issues新增内容: 燃尽图 照片
- mysql explain知道
- MySQL server PID file could not be found!
重启mysql提示MySQL server PID file could not be found! Starting MySQL...The server quit without updating ...
- Servlet作业2-将表单提交的商品信息输出到页面中
1,表单页面 shangpin.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- 【ASP.NET Identity系列教程(二)】运用ASP.NET Identity
注:本文是[ASP.NET Identity系列教程]的第二篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序 ...
- ES6新特性:let和const的使用
(声明, 本文的所有代码均在node的最新稳定版本v4.4.3中执行的, 如果在浏览器中执行请把JS的运行环境提升为ES6) 以前一直用var定义变量, 现在有了两种新的定义变量的方式, 1: let ...
- js-处理千分符
<html> <head> <title> JS千分位处理 </title> </head> <script> functi ...
- selenium+webdriver+python 中警告框的处理方法
在自动化测试过程中,经常会遇到弹出警告框的情况,如图所示: 在 WebDriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体做法是使用 ...