CF1091F New Year and the Mallard Expedition
题目地址: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的更多相关文章
- Good Bye 2018 (A~F, H)
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...
- Codeforces 1091 Good Bye 2018
占个坑先,希望不要掉的太惨了吧,不要掉到上一次之前的rating upt:flag竟然没到,开心. A - New Year and the Christmas Ornament 好像没什么可说的. ...
- Codeforces Good Bye 2018
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...
- POJ 2431 Expedition(优先队列、贪心)
题目链接: 传送门 Expedition Time Limit: 1000MS Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- poj 2431 Expedition
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12980 Accepted: 3705 Descr ...
- POJ 2431 Expedition (STL 优先权队列)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8053 Accepted: 2359 Descri ...
- Expedition(优先队列)
Expedition 点我 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9465 Accepted: 2760 Des ...
- poj 3431 Expedition 优先队列
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
随机推荐
- ajax传值修改数据
主界面代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- ansible 基础一
安装 解决依赖关系: yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto tar包安装 htt ...
- Hortonworks官网文档怎么找?
Hortonworks官网文档怎么找? 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 俗话说,授人予鱼不如授人予渔,网上部署HDP的部署方式的博客有很多,看得你是眼花缭乱的.其实万 ...
- 读写锁ReadWriteLock
为了提高性能,Java提供了读写锁,在读的地方使用读锁,在写的地方使用写锁,灵活控制,如果没有写锁的情况下,读是无阻塞的,在一定程度上提高了程序的执行效率. Java中读写锁有个接口java.util ...
- bzoj千题计划312:bzoj2119: 股市的预测(后缀数组+st表)
https://www.lydsy.com/JudgeOnline/problem.php?id=2119 题意:将给定数组差分后,求ABA形式的字串个数,要求|B|=m,|A|>0 1.后缀数 ...
- MySQL学习笔记(三)数据优化
第1章 数据库优化简介1-1 MySQL优化简介 第2章 SQL语句优化2-1 数据准备 2-2 MySQL慢查日志的开启方式 2-3 MySQL慢查日志分析工具之 mysqldumpslow www ...
- docker 系列 - 基础镜像环境和Docker常用命令整理
=======================docker 基础镜像环境 alpine=======================可以使用 docker search 命令搜索指定的 image, ...
- Newtonsoft.Json序列化字符串-格式化
转自:https://blog.csdn.net/wlphlj/article/details/51982866最近C#中需要将实体进行json序列化,使用了Newtonsoft.Json publi ...
- 梯度下降算法对比(批量下降/随机下降/mini-batch)
大规模机器学习: 线性回归的梯度下降算法:Batch gradient descent(每次更新使用全部的训练样本) 批量梯度下降算法(Batch gradient descent): 每计算一次梯度 ...
- Microsoft Windows .Reg File Dialog Box Message Spoofing 0day
Microsoft Windows .Reg文件对话框消息欺骗 0day 概述 扩展名为.reg的文件是Windows注册表中使用的注册文件.这些文件可以包含hives.密钥和值..reg文件可以在文 ...