ARC 098 C - Attention
Problem Statement
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if Si= E
, and west if Si= W
.
You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.
The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
Constraints
- 2≤N≤3×105
- |S|=N
- Si is
E
orW
.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of people who have to change their directions.
Sample Input 1
5
WEEWW
Sample Output 1
1
Assume that we appoint the third person from the west as the leader. Then, the first person from the west needs to face east and has to turn around. The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case. It is not possible to have 0 people who have to change their directions, so the answer is 1.
Sample Input 2
12
WEWEWEEEWWWE
Sample Output 2
4
Sample Input 3
8
WWWWWEEE
Sample Output 3
3 模拟题
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#define ll long long
using namespace std;
const int maxn=300005; int n,qz[maxn],tot,ans=1<<30;
char s[maxn]; int main(){
scanf("%d",&n),scanf("%s",s+1);
for(int i=1;i<=n;i++) qz[i]=qz[i-1]+(s[i]=='E');
tot=qz[n];
for(int i=1;i<=n;i++) ans=min(ans,(i-1-qz[i-1])+(tot-qz[i]));
cout<<ans<<endl;
return 0;
}
ARC 098 C - Attention的更多相关文章
- ARC 098 D - Xor Sum 2
Problem Statement There is an integer sequence A of length N. Find the number of the pairs of intege ...
- 【AtCoder】 ARC 098
link C-Attention 题意:一个字符队列,每个位置是\(W\)或\(E\),计算最小的修改数量,使得存在一个位置,它之前的都是\(E\),之后的都是\(F\) #include<bi ...
- AtCoder Regular Contest 098
AtCoder Regular Contest 098 C - Attention 题意 给定一个只包含"E","W"字符串,可以花一的花费使他们互相转换.选定 ...
- Xcode 新版本如何设置ARC
在刚刚开始学习IOS开发时,最好不要开启ARC,这样有助于学习内存管理,但不少刚刚接触Xcode的朋友可能会发现,当你使用最新版本的Xcode时,敲入release等代码时会提示报错.这是因为系统默认 ...
- Plastic Bottle Manufacturer Tips - Attention To Plastic Bottle Processing Technology
In fact, the processing technology of plastic bottles is actually quite strict. In fact, regular man ...
- Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCA ...
- 黑马程序员——ARC机制总结和用ARC建立模型
ARC 全称:Automatic Reference Counting 使用ARC 只需要在建立一个新的项目的时候把 下面的√打上 Xcode5以后都会默认建议开发者使用ARC机制 新的项目中如果有部 ...
- JSONKit在项目中使用设置(ARC与方法更新)
在项目中经常会遇到解析json的情况,如果有同学想要解析JSON,那么JSONKit可以是一个不错的选择. git中JSONKit 的地址为:https://github.com/johnezang/ ...
- MRC迁移ARC之__block
今日帮着同事把老项目从MRC迁移至ARC,大部分工作无非是删除release,[super dealloc]等方法,只要关闭了MRC编译选项后,编译器能自动帮你检查,block就有一些不一样了,发现许 ...
随机推荐
- Leetcode 659.分割数组为连续子序列
分割数组为连续子序列 输入一个按升序排序的整数数组(可能包含重复数字),你需要将它们分割成几个子序列,其中每个子序列至少包含三个连续整数.返回你是否能做出这样的分割? 示例 1: 输入: [1,2,3 ...
- CentOS修改IP地址
一.CentOS 修改IP地址修改对应网卡的IP地址的配置文件 # vi /etc/sysconfig/network-scripts/ifcfg-eth0 电信 # vi /etc/syscon ...
- DB2数据库的日志文件管理
DB2数据库的日志文件管理 DB2的日志模式 1.1循环日志 当循环日志生效时,事务数据将通过循环的方式写入主要日志文件.当存储于某个日志文件中的所有记录都不再需要用于恢复时,该日志文件将被重用,并且 ...
- vim使用的一些积累
vi visual interfacevim vi improved vim模式:编辑模式(命令模式)输入模式末行模式 编辑模式下,zz保存并退出移动光标:(编辑模式)1.逐字符移动 h 左 l 右 ...
- pyinstaller打包自己的python程序
使用Pyinstaller打包步骤如下 1. 安装pyinstaller pip install pyinstaller 查看安装的版本 pyinstaller --version 2. 给脚本加密 ...
- JDK从1.8.x升级到9.0.1后Tomcat 8.0.x不能启动
目录 描述 具体环境情况 处理办法 描述 JDK在今年9月发布后,我们项目也打算测试升级使用JDK 9.在我将JDK升级成 JDK 9.0.1后,启动tomcat失败(黑框一闪就没了).具体失败信息如 ...
- 【bzoj2044】三维导弹拦截 dp+二分图最大匹配
题目描述 n个物品,第i个位置有ai.bi.ci三种属性.每次可以选出满足$\ a_{p_i}<a_{p_{i+1}}\ ,\ b_{p_i}<b_{p_{i+1}}\ ,\ c_{p_i ...
- 【bzoj3831】[Poi2014]Little Bird 单调队列优化dp
原文地址:http://www.cnblogs.com/GXZlegend/p/6826475.html 题目描述 In the Byteotian Line Forest there are t ...
- hdu 2510 符号三角形 (DFS+打表)
符号三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- REST Web 服务(一)----REST 介绍
1. 什么是REST? REST 定义了一组体系架构原则,您可以根据这些原则设计以系统资源为中心的 Web 服务,包括使用不同语言编写的客户端如何通过 HTTP 处理和传输资源状态. 2. REST的 ...