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 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
随机推荐
- ansible的主机的默认配置部分
Ansible默认安装好后有一个配置文件/etc/ansible/ansible.cfg,该配置文件中定义了ansible的主机的默认配置部分,如默认是否需要输入密码.是否开启sudo认证.actio ...
- Nginx+Keeplived双机热备(主从模式)
Nginx+Keeplived双机热备(主从模式) 参考资料: http://www.cnblogs.com/kevingrace/p/6138185.html 双机高可用一般是通过虚拟IP(漂移IP ...
- bzoj1233 单调队列优化dp
https://www.lydsy.com/JudgeOnline/problem.php?id=1233 数据结构优化dp的代码总是那么抽象 题意:奶牛们讨厌黑暗. 为了调整牛棚顶的电灯的亮度,Be ...
- golang 热升级
需求场景 干净利落地升级正在运行的agent程序.适用于Devops团队. 目标: 不关闭现有连接:例如我们不希望关掉已部署的运行中的程序.但又想不受限制地随时升级服务. 新的进程要能够启动并替换掉旧 ...
- Thymeleaf中的&&解析问题
1.问题: 最近使用了新的html模板thymeleaf..在模板里使用js语法时遇到问题,&&不能正确的被解析,使用if(a&&b){}可以通过模板解析,但是浏览器上 ...
- 利用salt搭建hadoop集群
自动化工具有很多..今天总结一下salt安装hadoop 步骤,学习过程. 1,机器列表 hosts文件 只需要将namenode的两台机器上配置 ,不解释了. 2.salt-master在10 ...
- Dubbo服务端结合maven打jar包
<build> <finalName>odao-weixin-user</finalName> <resources> ...
- ubuntu主题收集
ubuntu主题收集 一些cmd常用命令: 任务栏底部,进入Dash并打开终端,命令最后一个是参数可选 ( Left | Bottom ) gsettings set com.canonical.Un ...
- windows server 2008 r2 负载平衡 找不到主机 解决方案
在C:\Windows\System32\drivers\etc文件夹中的host文件里手工将主机名WIN-********解析至IP 即可.
- j2ee应用开发调试工具
j2ee应用程序不能独立运行,需要运行在一个servlet/jsp容器中,常用的servlet/jsp容器如:tomcat,jetty等.在开发调试j2ee程序时,也需要部署在一个指定的容器中.如果每 ...