题目链接

题意:看一个图片需要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(二分)的更多相关文章

  1. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  2. 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) ...

  3. Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  4. 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 ...

  5. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  6. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  7. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  8. 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 ...

  9. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

随机推荐

  1. window 运行指令(1)

    添加或删除程序 appwiz.cpl 管理工具 control admintools Bluetooth文件传送向导 fsquirt 计算器 calc 证书管理控制台 certmgr.msc 字符映射 ...

  2. spring+mybaties+springMvc+slf4j所需jar包

  3. 【JavaEE企业应用实战学习记录】MyGetAttributeListener

    package sanglp.servlet; import javax.servlet.ServletContext; import javax.servlet.ServletContextAttr ...

  4. PHP-- 三种数据库随机查询语句写法

    1. Oracle,随机查询查询语句-20条 select * from (  select  *  from 表名 order by dbms_random.value ) where rownum ...

  5. 17-tail 简明笔记

    显示文件的最后一部分(尾部) tail [options] [file-list] 参数 file-list是tail要显示的文件的路径名列表.当制定多个文件时,tail在显示每个文件的内容之前先显示 ...

  6. 使用ContentProvider进行应用程序间的数据交互

    什么是ContentProvider: ContentProvider用来管理数据的访问规则.它允许你的应用程序向外界暴露需要被访问的数据. 是Android的四大组件之一. ContentProvi ...

  7. android第三方框架 xlistview 的使用

    如今上拉刷新,下拉加载更多已经是浩如烟海的app的标配了 最近正好有相关的需要就去学习了一下,还是那句老话凡事都靠自己来 搞实在不是一件好事,费时费力不说可能还是在做无用功,不过自己研究学习 还是很有 ...

  8. Linux内核参数配置

    Linux在系统运行时修改内核参数(/proc/sys与/etc/sysctl.conf),而不需要重新引导系统,这个功能是通过/proc虚拟文件系统实现的. 在/proc/sys目录下存放着大多数的 ...

  9. 【转】HTTP协议详解

    原文地址:http://www.cnblogs.com/EricaMIN1987_IT/p/3837436.html 一.概念 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则 ...

  10. 100722C

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...