Regionals 2014 >> Latin America 6822 - Black a

【PX4学习笔记】1. ROS及PX4环境搭建 环境 Ubuntu18.04 安装教程参考 https://www.guyuehome.com/8983 安装过程中问题的解决 问题1 rosdep init 错误的终极解决方法 注意etc/下的ros和rostep文件夹要自己建 问题2 Ubuntu安装ROS报错 sudo: rosdep:找不到命令 问题3(更好地解决了问题1、2)【推荐】 解决GitHub的raw.githubusercontent.com无法连接问题 问题4:GeographicLib的安装 教程中安装GeographicLib d 阅读详情
6822
Black and white stones
Shagga and Dolf like to play a game with stones, each of which is either black or white. At the beginning
of the game, Dolf arranges all the stones in a single line from left to right. Then, Shagga’s goal is to
reorder the stones so that all the black stones are to the left of all the white stones. To do this, he
can choose any pair of stones of different color and swap their positions, paying A coins to Dolf in the
process. However, if the two stones whose positions he is swapping are adjacent, Dolf must give him a
refund of B coins, meaning that the operation will effectively cost Shagga only A − B coins.
Shagga is not very bright, so he hasn’t realized yet that he will only loose coins while playing this
game. However, he is aware of his limitations, so he knows that if he played optimally he would loose
fewer coins than he is loosing right now, with his strategy of randomly choosing the stones he swaps in
each movement. Therefore, he wants to know the minimum number of coins he will have to pay Dolf
in order to get to the desired arrangement of stones, and is threatening to feed you to the goats if you
don’t help him.
Input
The input contains several test cases; each test case is formatted as follows. The first line contains two
integers A and B (0 ≤ B < A ≤ 106), representing respectively the cost of swapping two stones and
the value of the refund when swapping adjacent stones. The second line contains a non-empty string
S of at most 5000 characters. The i-th character of S indicates the color of the i-th stone, from left to
right, in the initial arrangement of the stones. The character is either the uppercase letter ‘B’ or the
uppercase letter ‘W’, indicating respectively a black or a white stone.
Output
For each test case in the input, output a line with an integer representing the minimum number of coins
Shagga will have to pay Dolf in order to arrange the stones such that all the black ones are to the left
of all the white ones.
Sample Input
2 1
BWWB
5 3
WBWWBWBWBWBBBWWBBB
1000000 0
W
Sample Output
2
27

0


题意:把所有的黑色(B)移到左边、白色(W)移到右边的最小花费。每交换,花费为a,若交换的为相邻位置则只需花费a-b

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <vector>
using namespace std;

typedef long long ll;
#define MAX 20005
#define PI acos(-1.0)
ll min(ll a,ll b){
	if(a > b) return b;
	else return a;
}
ll f[50005]; //在此位置前(包含自己)有多少个B 
ll cnt[50005]; //在第i个B前有多少个W 
int main(){
	ll a,b;
	while(~scanf("%lld%lld", &a, &b)){
		string s;
		cin >> s;
		ll len = (ll)s.size();
		ll tot = 0;
		b = a-b;
		memset(f,0,sizeof(f));
		memset(cnt,0,sizeof(cnt));
		int n = 1;
		for(ll i = 0;i < len;i++){
			if(s[i] == 'B'){
				f[i] = 1;
				cnt[n] = tot;
				n ++;
			}
			else{
				cnt[n] = ++tot;
			}
		}
		n --;
		for(ll i = 1;i < len;i++) f[i] += f[i-1];
		for(ll i = 1;i <= n;i++) cnt[i] += cnt[i-1];
		ll mmin = b*cnt[n];
		for(ll i = 0;i < len;i++){
			if(s[i] == 'W'){
				ll tmp = i+1-f[i];  //在此i前有多少个W(包括自己) 
				if(n-tmp-f[i] < 0) break;  //注意跳出 
				//cout << mmin << " " << tmp*a << " " << b << " " << cnt[n-tmp]-cnt[f[i]] << " " << n-tmp-f[i] << endl;
				mmin = min(mmin,tmp*a+b*(cnt[n-tmp]-cnt[f[i]]-tmp*(n-tmp-f[i])));
			}
		}

		printf("%lld\n", mmin);
	}
	return 0;
}
/*4 3
BWWWWWBWBWBWWBWBWBWWWB
6 2
BWWBWBWWWBWBBBBW
*/




一分钟详解PCL中点云配准技术 原文首发于微信公众号「3D视觉工坊」: 一分钟详解PCL中点云配准技术 本文是对前两篇文章:点云配准(一 两两配准)以及3D点云(二 多福点云配准)的补充,希望可以在一定程度上帮助大家对点云配准理解地更为深刻。 一 PCL中点云配准技术的简单实现 在同一文件夹下,有测试数据文件monkey.ply,该文件是利用Blender创建的默认Monkey模型。 利用如下代码,将初始点云(图中绿色点云)... 阅读详情

相关推荐

macOS 12.7.6部署Ollama+Dify避坑指南

本文介绍了在macOS 12.7.6系统下部署Ollama和Dify的详细步骤及避坑指南。主要内容包括:1)关闭系统完整性保护(SIP)以允许修改系统目录;2)安装特定版本的Docker(2.1.0.5)和docker-compose(v2.38.2)以避免兼容性问题;3)配置Ollama服务并下载nomic-embed-text和deepseek-r1:7b模型;4)针对macOS调整Dify的docker配置文件,包括延长超时时间、修改存储路径、增加资源限制等关键设置。文中提供了完整的命令操作步骤和配置

Hi20240217的博客 3127

现代大学英语精读第二版(第二册)学习笔记(原文及全文翻译)——2B - Arrangement in Black and White(安排黑人与白人的会面)

Unit 2B -Arrangement in Black and White Arrangement in Black and White Dorothy Parker The woman with the pink velvet poppies twined round the gold of her hair crossed the crowded room and clutched the lean arm of her host. "Now I got you!" she said. ".

预见未来to50的专栏 1万+

ESP-CSI:使用ESP32进行CSI(信道状态信息)采集

使用esp32进行csi(信道状态信息)采集和处理

capsize的博客 8301

大学英语精读第三版(第五册)学习笔记(原文及全文翻译)——8B - Conflict in Black and White(黑人与白人的冲突)

Unit 8B - Conflict in Black and White Conflict in Black and White Lewis. Levine & Lucinda S. Hughey Black and white. In the United States these two colors have been the source of racial conflict since the early 1600s. It was at that time that the fi

预见未来to50的专栏 6966

恒定跨导的奥秘:基于1:3电流镜的轨到轨运放输入级设计与仿真验证

本文深入探讨了基于1:3电流镜的轨到轨运放输入级设计,重点分析了恒定跨导(GM)的实现原理与仿真验证。通过精确的电流补偿机制和工艺参数优化,解决了传统运放在电源轨附近跨导下降的问题,为模拟集成电路设计提供了可靠的低电压解决方案。

weixin_33686714的博客 527

告别手动群发!用IDA Pro和CE搞定企业微信4.1.38.6011的HOOK开发(附完整代码)

本文详细介绍了如何利用IDA Pro和Cheat Engine进行企业微信4.1.38.6011的HOOK开发,实现自动化群发功能。从逆向工程环境配置、关键函数定位到HOOK框架设计,提供完整代码示例,帮助企业提升运营效率。

weixin_42533120的博客 486

【补题笔记】AtCoder Beginner Contest 256 A~Ex

我也有即使赌上性命,也要守护的东西。 ——《名侦探柯南》安室透

xhyu61的博客 1623

window部署open claw(使用wsl-Ubuntu-docker部署)

本文详细介绍了在Windows 11系统下通过WSL2+Docker部署OpenClaw的完整流程。首先需要满足硬件配置要求并开启虚拟化功能,然后依次完成WSL2安装配置、Docker Desktop安装、OpenClaw镜像拉取等步骤。重点说明了端口映射、socat转发配置及openclaw.json文件修改方法。最后通过验证WSL2内网IP和端口访问服务。该方案具有最佳兼容性,能有效避免Windows环境下的依赖冲突问题。

Kmoyic的博客 2779

Game with string

栈

a free man 1080

Fakra连接器封装的PCB处理方式分析与总结

以往的项目中,关于Fakra连接器封装焊盘的PCB处理方式一直未有明确的规则定义,不同的处理方式,产生的效果各不相同,严重影响到设计的一致性,为此,本文针对这一设计上的缺陷进行了量化分析: 以十层板设计为例,分别从插入损耗(IL)、回波损耗(RL)、特性阻抗(Z0)三个维度进行了分析对比,最终,总结出适合的PCB设计规则,并且,该规则也适用于十层以外的叠构设计。

一只豌豆象的博客 2249

CNN+LSTM+Attention+DNN模型实战:pytorch搭建CNN+LSTM+Attention+DNN行车速度预测

CNN+LSTM+Attention+DNN模型实战:pytorch搭建CNN+LSTM+Attention+DNN行车速度预测

6048

Codeforces-B-Game with string(模拟栈)

Two people are playing a game with a stringss, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete the...

weixin_30781775的博客 224

【系统架构设计师】论文模板样例:论软件系统架构风格

本人于年月参与项目,该系统为*,在该项目组中我担任系统架构师岗位,主要负责系统整体架构设计。本文以该车联网项目为例,主要讨论了软件架构风格在该项目中的具体应用。底层架构风格我们采用了虚拟机风格中的解释器,因该公交共有几十种不同的数据协议,使用解释器风格可以满足整车数据协议兼容性需求;中间层关于应用层的数据流转采用了独立构件风格中的隐式调用,以减低系统间耦合度、简化软件架构,提高可修改性方面的架构属性;应用系统层采用了B/S的架构风格,统一解决公交行业性难题“实施推广难、维护难”问题。

数据知道的博客 9941

ABC047&ARC063.1D Reversi

问题 E: 1D Reversi时间限制: 1 Sec  内存限制: 128 MB提交: 332  解决: 139[提交][状态][讨论版][命题人:admin]题目描述Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and whi...

红鲤鱼与绿鲤鱼与驴 694

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Black And White ---HDU 3911

Problem Description There are a bunch of stones on the beach; Stone color is white or black. Little Sheep has a magic brush, she can change the color of a continuous stone, black to white, white to bl...

青烟绕指柔的博客 512

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Black And White

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3911 Black And White Problem Description There are a bunch of stones on the beach; Stone color is white or black. Little Sheep has a

vip_wesley 452

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Codeforce 1104B 字符串思维题 类回文(栈)

Game with string TimeLimit:1000MS MemoryLimit:256MB 64-bit integer IO format:%I64d 已解决 | 点击收藏 Problem Description Two people are playing a game with a string s, consisting of lowercase latin letters....

0xFFFFINF 274

B. Game with string(cf)STL:stack

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two people are playing a game with a string ss, consisting of lowercase latin lette...

nuoyanli的博客 1818

第十三周比赛

6822 Black and white stones Shagga and Dolf like to play a game with stones, each of which is either black or white. At the beginning of the game, Dolf arranges all the stones in a single line from le...

Allen的博客 255

2017ICPC hongkang B题Black and White(线段树线扫描)

计蒜客题目:https://nanti.jisuanke.com/t/19926Considerasquaremapwith N \times NN×N cells. We indicate the coordinate of a cell by(i,j)(i,j),where 1 \le i,j \le N1≤i,j≤N. Each cell has a color either white o...

雪的期许 980

Codeforces Round #534 (Div. 2)______B. Game with string[字符串,模拟]

Two people are playing a game with a string ss, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, ...

xiang_hehe的博客 583

CodeForces A. Letters Cyclic Shift【字符串】

A. Letters Cyclic Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a non-empty string s c

所谓梦想,就是永不停息的疯狂。。。。。 1810

蓝桥杯寒假训练----3

大提琴的声音就像一条河,左岸是我无法忘却的回忆,右岸是我值得紧握的璀璨年华,中间流淌的,是我年年岁岁淡淡的感伤。 蚂蚁感冒 长100100厘米的细长直杆子上有nn只蚂蚁。它们的头有的朝左,有的朝右。 每只蚂蚁都只能沿着杆子向前爬,速度是11厘米/秒。 当两只蚂蚁碰面时,它们会同时掉头往相反...

0k-ok 593

百度之星2015初赛(1)1002 HDOJ5247 找连续数(暴力 简单做法)

找连续数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 819    Accepted Submission(s): 300 Problem Description 小度熊拿到了一个无序的数组,对于这个数组,小度熊想知道

Pashudeanan的专栏 1185

CF527A Playing with Paper

A. Playing with Paper time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Vasya was sitting on a not so

Pashudeanan的专栏 1116

6886 - Golf Bot

6886 Golf Bot Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that will never miss a shot. I simply place it over the ball, choose the rig

Pashudeanan的专栏 1099
上一篇: 6886 - Golf Bot
下一篇: Regionals 2014 >> Latin America
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值