题目地址:CF1091F New Year and the Mallard Expedition

题意比较复杂,整理一下:

\(n\) 段,每段有两个属性:长度,地形(G,W,L)

有三种运动方式:

1.游泳:W,3m/s,+1

2.走路:G,5m/s,+1

3.飞行:G,W,L,1m/s,-1

思路:贪心

需要解决两个问题:

1、遇到L时没体力飞行

解决的方法很简单:在之前的某个地方向后游泳或走路半米,再向前半米,这样可以+1

显然,游泳比走路更优,因此我们在第一次遇到W时完成所需的所有+1

当然,如果在此之前没有遇到W,则只能走路来+1

2、最后剩下部分体力

解决的方法也很简单:尽可能的将之前的运动用飞行代替,优先代替走路

注意,代替一次将会-2,同时也不能过早的代替以防止体力耗尽的情况发生

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100006;
ll a[N];
string s;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    cin >> s;
    bool flag = 0;
    ll ans = 0, k = 0, num = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') {
            flag = 1;
            k += a[i];
            ans += 3 * a[i];
        } else if (s[i] == 'G') {
            k += a[i];
            ans += 5 * a[i];
            num += (a[i] << 1);
        } else {
            ans += a[i];
            k -= a[i];
            if (k < 0) {
                ans -= k * (flag ? 3 : 5);
                k = 0;
            }
        }
        num = min(num, k);
    }
    if (k > 0) ans -= (num << 1) + (k - num);
    cout << ans << endl;
    return 0;
}

CF1091F New Year and the Mallard Expedition的更多相关文章

  1. Good Bye 2018 (A~F, H)

    目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...

  2. Codeforces 1091 Good Bye 2018

    占个坑先,希望不要掉的太惨了吧,不要掉到上一次之前的rating upt:flag竟然没到,开心. A - New Year and the Christmas Ornament 好像没什么可说的. ...

  3. Codeforces Good Bye 2018

    咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...

  4. POJ 2431 Expedition(优先队列、贪心)

    题目链接: 传送门 Expedition Time Limit: 1000MS     Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...

  5. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  6. poj 2431 Expedition

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12980   Accepted: 3705 Descr ...

  7. POJ 2431 Expedition (STL 优先权队列)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8053   Accepted: 2359 Descri ...

  8. Expedition(优先队列)

    Expedition 点我 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9465   Accepted: 2760 Des ...

  9. poj 3431 Expedition 优先队列

    poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...

随机推荐

  1. 字节转字符 OutputStreamWriter

    package cn.lideng.demo4; import java.io.FileNotFoundException; import java.io.FileOutputStream; impo ...

  2. day-03(js)

    回顾: css: 层叠样式表 作用: 渲染页面 提供工作效率,将html和样式分离 和html的整合 方式1:内联样式表 通过标签的style属性 <xxx style="...&qu ...

  3. 干货分享:互联网运营 学习SEO从零开始 SEO深度解析学习笔记

    最近在自学SEO,互联网运营,把做的笔记干货分享给大家啊! 希望能帮到大家,如有好的建议可以关注我[磨人的小妖精]或留言,大家一起探讨. 之前还写过一篇文章互联网运营+SEO:推荐必看的5本书籍,学习 ...

  4. java io系列19之 CharArrayWriter(字符数组输出流)

    本章,我们学习CharArrayWriter.学习时,我们先对CharArrayWriter有个大致了解,然后深入了解一下它的源码,最后通过示例来掌握它的用法. 转载请注明出处:http://www. ...

  5. window.location.reload();页面实现跳转和刷新

    1 history.go(0)2 location.reload()3 location=location4 location.assign(location)5 document.execComma ...

  6. excel怎么比较两组或两列数据的相同项和不同项

    https://jingyan.baidu.com/article/c843ea0b7a2a7477921e4a47.html

  7. 阿里Fastjson的使用

    Fastjson是一个Java语言编写的高性能功能完善的JSON库.由阿里巴巴公司团队开发的. 主要特性主要体现在以下几个方面: 1.高性能 fastjson采用独创的算法,将parse的速度提升到极 ...

  8. mysql创建用户与pymsql模块

    mysql 创建用户及增删改查 创建mysql 用户 with grant option 表示用户不存在自主创建 grant [ select ……,insert ……| all ] on 库名.表名 ...

  9. vue-router导航钩子

    Vue路由中的导航钩子,可以用来拦截导航,让它完成跳转. 全局导航钩子 当一个导航触发时,全局的 before 钩子按照创建顺序调用.钩子是异步解析执行,此时导航在所有钩子 resolve 完之前一直 ...

  10. java基础之自定义异常类及throw和throws的区别

    一.异常的架构: Throwable类:所以异常类都是Throwable的子类,它派生两个子类 Error和Exception. Error类:表示仅靠程序本身无法恢复的的严重错误,比如内存溢出,虚拟 ...