【Codeforces】-632B-Alice, Bob, Two Teams(模拟,思维)

从Applied Intelligence被拒到The Visual Computer录用:我的计算机视觉论文投稿时间线全记录(含详细修改意见) 本文详细记录了作者从Applied Intelligence被拒到The Visual Computer成功发表计算机视觉论文的全过程,重点分享了如何将模糊的拒稿理由转化为具体改进方案。文章包含技术改进细节、写作调整策略以及期刊选择经验,为计算机视觉领域的研究者提供了实用的投稿指南。 阅读详情

B. Alice, Bob, Two Teams
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi.

The way to split up game pieces is split into several steps:

  1. First, Alice will split the pieces into two different groups A and B. This can be seen as writing the assignment of teams of a piece in an n character string, where each character is A or B.
  2. Bob will then choose an arbitrary prefix or suffix of the string, and flip each character in that suffix (i.e. change A to B and B to A). He can do this step at most once.
  3. Alice will get all the pieces marked A and Bob will get all the pieces marked B.

The strength of a player is then the sum of strengths of the pieces in the group.

Given Alice's initial split into two teams, help Bob determine an optimal strategy. Return the maximum strength he can achieve.

Input

The first line contains integer n (1 ≤ n ≤ 5·105) — the number of game pieces.

The second line contains n integers pi (1 ≤ pi ≤ 109) — the strength of the i-th piece.

The third line contains n characters A or B — the assignment of teams after the first step (after Alice's step).

Output

Print the only integer a — the maximum strength Bob can achieve.

Examples
input
5
1 2 3 4 5
ABABA
output
11
input
5
1 2 3 4 5
AAAAA
output
15
input
1
1
B
output
1
Note

In the first sample Bob should flip the suffix of length one.

In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5.

In the third sample Bob should do nothing.


题意::题目是说从前或从后选一个子串(必须包括首或者尾,长度任意),把A变B,B变A,然后计算B的总价值,使之最大。

题解:先统计不变时B的价值,然后从前从后各扫一遍就行了

sum1记录从前到后变化A B,值的变化。sum2记录从后到前变化......

如:从前到后扫一遍,i=3,那么sum1就继续改变(i=1,i=2 .A变成B,B变成A已经记录),再更新ans

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
int a[500010];
char s[500010];
int main()
{
	int n;	
	while(~scanf("%d",&n)) 
	{
		__int64 ans=0,sum1,sum2;
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);	
		scanf("%s",s+1);
		for(int i=1;i<=n;i++)
		{
			if(s[i]=='B')
				ans+=a[i];
		}
		sum1=ans;
		sum2=ans;
		for(int i=1;i<=n;i++)	//从前到后一个for循环,两个for会超时.要包括首以及i之前的字母那么sum1就一直更新就好 
		{
			if(s[i]=='A')		
				sum1+=a[i];
			else
				sum1-=a[i];
			ans=max(ans,sum1);
		}
		for(int i=n;i>=1;i--)
		{
			if(s[i]=='A')
				sum2+=a[i];
			else
				sum2-=a[i];
			ans=max(ans,sum2);
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


遥感生态指数(RSEI)——四个指数的计算 遥感生态指数是在4个生态指数的基础上通过主成分变换得出的一个评价生态环境质量的指标。因此,第二部分就是要分别计算出这4个指数的值。 ①首先,是绿度指数的计算,一般用归一化植被指数(NDVI) NDVI=(NIR-Red)/(NIR+Red) 在Bandmath工具中输入NDVI计算公式 (float(b4-b3))/(b4+b3) 其中,b3、b4分别是红波段和近红外波段 ②其次,是湿度计算。 WET = c1B1 + c2B2 + c3B3... 阅读详情

相关推荐

Unity 2D精灵点击交互实现:从BoxCollider 2D到Event Trigger的完整指南

本文提供了Unity 2D精灵点击交互的完整实现指南。通过详细拆解BoxCollider 2D与Event Trigger两大核心组件的协同工作原理,手把手教你为Sprite Renderer添加点击、悬停等事件响应。文章包含从基础配置到进阶优化、性能调试的实战步骤,帮助开发者高效实现游戏世界内的对象交互,是Unity 2D开发的实用教程。

ansible6ops的博客 312

edu round 9 B-Alice, Bob, Two Teams

B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob are playing a game.

菜鸟起飞的平台 617

ESP32+micro-ROS机器人开发实战:轻量级ROS2嵌入式集成

ROS2是现代机器人软件栈的核心框架,其基于DDS的分布式通信与QoS保障能力为多节点协同提供基础支撑;而micro-ROS作为专为微控制器优化的ROS2兼容中间件,解决了资源受限设备(如ESP32)接入ROS2生态的关键难题。其通过分层架构将DDS通信下沉至上位机Agent,使MCU仅需运行轻量Client,大幅降低内存开销(实测<180KB)并保留标准ROS2接口语义。该方案广泛应用于教育机器人、移动底盘、传感器节点等嵌入式场景,尤其适合基于ESP-IDF开发的Wi-Fi/BLE物联网机器人系统。本文以

weixin_29025501的博客 414

Alice, Bob, Two Teams

Description Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces

hello world 542

大模型的安全发展与安全治理

2022 年底,OpenAI 推出的 ChatGPT 在文本生成领域实现了重大突破,引领了大模型技术的发展方向,推动了各式各样的基座大模型及行业大模型的发展,并逐步向多模态和具身化方向迅速演进。显然,大模型展现出的强大能力为人工智能通用化揭开了序幕。然而,大模型技术的安全性也面临着生成内容的安全性、伦理道德等重大挑战。只有积极确保大模型的安全性,才能更有效地推动其持续发展,进而更好地应对大模型技术变革所带来的机遇与挑战。

qq_41432686的博客 2587

第4章 Stata参数检验

目录 4.1单一样本T检验 案例延伸 4.2独立样本T检验 案例延伸 1.改变置信水平 2.在异方差假定条件下进行假设检验 4.3配对样本T检验 案例延伸 1.改变置信水平 4.4单一样本方差的假设检验 案例延伸 4.5双样本方差的假设检验 参数检验(Parameter Test)是指对参数的平均值、方差、比率等特征进行的统计检验。参数检验一般假设统计总体的具体分布为已知,但是其中一些参数或者取值范围不确定,分析的主要目的是估计这些未知参数的取值,或者对这些参数进...

qq_45112156的博客 1万+

CodeForces 632 B.Alice, Bob, Two Teams(水~)

Description 有n个物品,分为A和B两种,每个物品有一个价值pi,Bob可以把任意一个前缀或者后缀中所有A物品变成B物品,B物品变成A物品,之后Bob拿到所有B物品,问Bob能拿到的物品的最大价值 Input 第一行一整数n表示物品数量,之后n个整数pi表示第i个物品的价值,最后一个长度为n的字符串表示每个物品的种类(1<=n<=5e5,1<=pi<=1e9) Output 输出

ZSQ 492

Deepseek Engram 论文全面解读

以下是对 DeepSeek 与北京大学于联合发布的论文《》(简称Engram 论文)的。

lpfasd123的博客 371

CodeForces-632B-Alice, Bob, Two Teams

B - Alice, Bob, Two Teams Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u SubmitStatusPracticeCodeForces 632B Description Alice and Bob are playing a game. The game in

Prim 567

IC 笔试真题之吾见——华为实习(1)

前言 今天(2022 04 07)刚建立了一个专栏《IC真题之吾见》,准备记录一些IC真题的见解,为以后找工作做一点准备。 刷题绝不是目的,以题代练,以题代学。 题目来自师兄申请 华为实习“设计”岗位 的笔试真题。 见解大部分来自自己学习的理解,也有部分超纲知识是网络检索得到,希望可以多多在评论区留言交流,共同进步! 有问题的地方也希望可以直接批评指正! 后面也会同步更新此专栏! 1、下列有关时序分析的描述正确的是() A. recovery时间,是指异步控制信号在有效时钟沿到达之后必须保持

记录所学,分享知识,结识挚友 8642

【速通RAG实战:索引】4.RAG文档解析技术

通过本文技术方案,可构建高精准、高效率的文档解析流水线,为 RAG 应用提供坚实的知识底座。核心在于**格式解析的鲁棒性**和**语义分块的准确性**,后续通过持续的性能优化和质量监控,逐步提升索引质量和检索效率。

2025博客之星Top81。专注AI工程化与架构实战。从分布式思维到模型部署,用工程化视角为你厘清AI落地的真实路径。 1553

【CodeForces - 632B】【Alice, Bob, Two Teams】(前缀和求最优差值)

题目: Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces is split in...

哇哈哈哈的博客 424

基于 Qt C++ 的智能工厂数字孪生系统

你想要实现一个基于 Qt C++ 的智能工厂数字孪生系统,核心是 **Qt 3D** 场景搭建 + **实时数据驱动** 设备模型。下面我将为你提供一个完整的解决方案,包含 **核心思路、实现步骤、完整代码示例** 和 **注意事项**。| **渲染层** | 3D 场景搭建、设备模型加载、实时动画渲染、用户交互。| **业务逻辑层** | 数据处理(滤波、转换)、设备状态管理、动画逻辑控制。| **数据层** | 实时采集设备数据(如传感器、PLC、MES 系统),提供数据接口。

寒寒豆豆软件公司的博客 201

codeforces-632B-Alice, Bob, Two Teams

632B-Alice, Bob, Two Teams

Linoy 899

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Codeforces 632B Alice, Bob, Two Teams 【水题】

B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob are playing a game

世界很大 934

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【CodeForces】632B - Alice, Bob, Two Teams(模拟)

点击打开题目 B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob are

wyg1997 534

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

CodeForces 632B Alice, Bob, Two Teams

B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob are playing a game

lu_1110的博客 314

【codeforces 632B Alice, Bob, Two Teams】

Alice, Bob, Two TeamsDescription Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi.The way to split

楚江枫 554

CoderForces 632B Alice, Bob, Two Teams

Alice, Bob, Two Teams Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 632B Description Alice and Bob are playing a gam

※夏日星空※ 263

CodeForces 632B Alice, Bob, Two Teams

题意:有n个物品,每个物品有一个分值,然后每个物品有一个标牌,如果标牌上是A,那么就属于A,是B,那么就属于B。现在你可以选择一个前缀或者后缀,然后将上面的A改成B,将B改成A,然后问你最多B能够得到多少 思路:分别记录前缀和.. #include #include #include #include #include #include #include #i

围巾的ACM博客 575

【CodeForces】 632B Alice, Bob, Two Teams

B. Alice, Bob, Two Teams time limit per test  1.5 seconds memory limit per test  256 megabytes input  standard input output  standard output Alice and Bob are playing a

better_space的博客 290

CodeForces-632B Alice, Bob, Two Teams 【dp】

Alice, Bob, Two Teams Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u   Description Alice and Bob are playing a game. The game involves splitting up game pieces into two team

DTL66的博客 386

CodeForces 632B Alice, Bob, Two Teams(暴力)

B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob are playing a game

qq_35634181的博客 259

Alice, Bob, Two Teams---CodeForces - 632B (前后缀)

Alice, Bob, Two Teams Time limit 1500 ms Memory limit262144 kB Alice and Bob are playing a game. The ga...

From now on...的Blogs 266

codeforces_632B. Alice, Bob, Two Teams

B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob are playing a game

凳子 419

CodeForces 632BAlice, Bob, Two Teams

Description Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces i

菜鸟的自我修养 299
上一篇: 【HDU】-1286-找新朋友(欧拉函数)
下一篇: 【Codeforces】-660A-Co-prime Array(数学)
Bear1997
博客等级 码龄11年 55粉丝 369原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值