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 or W.

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的更多相关文章

  1. 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 ...

  2. 【AtCoder】 ARC 098

    link C-Attention 题意:一个字符队列,每个位置是\(W\)或\(E\),计算最小的修改数量,使得存在一个位置,它之前的都是\(E\),之后的都是\(F\) #include<bi ...

  3. AtCoder Regular Contest 098

    AtCoder Regular Contest 098 C - Attention 题意 给定一个只包含"E","W"字符串,可以花一的花费使他们互相转换.选定 ...

  4. Xcode 新版本如何设置ARC

    在刚刚开始学习IOS开发时,最好不要开启ARC,这样有助于学习内存管理,但不少刚刚接触Xcode的朋友可能会发现,当你使用最新版本的Xcode时,敲入release等代码时会提示报错.这是因为系统默认 ...

  5. 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 ...

  6. 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 ...

  7. 黑马程序员——ARC机制总结和用ARC建立模型

    ARC 全称:Automatic Reference Counting 使用ARC 只需要在建立一个新的项目的时候把 下面的√打上 Xcode5以后都会默认建议开发者使用ARC机制 新的项目中如果有部 ...

  8. JSONKit在项目中使用设置(ARC与方法更新)

    在项目中经常会遇到解析json的情况,如果有同学想要解析JSON,那么JSONKit可以是一个不错的选择. git中JSONKit 的地址为:https://github.com/johnezang/ ...

  9. MRC迁移ARC之__block

    今日帮着同事把老项目从MRC迁移至ARC,大部分工作无非是删除release,[super dealloc]等方法,只要关闭了MRC编译选项后,编译器能自动帮你检查,block就有一些不一样了,发现许 ...

随机推荐

  1. python学习总结---函数使用 and 装饰器

    # 函数使用 ### 零碎知识 - 灵活的if-else ```python a = 3 if False else 5 print(a) ''' if False: a = 3 else: a = ...

  2. http和Tcp的长连接和短连接

    . http协议和tcp/ip 协议的关系(1) http是应用层协议,tcp协议是传输层协议,ip协议是网络协议.(2) IP协议主要解决网络路由和寻址问题(3) tcp协议主要解决在IP层协议之上 ...

  3. weex & web app & vue

    weex & web app & vue https://weex-project.io/tools/playground.html https://weex.apache.org/ ...

  4. 主流 NoSQL 数据库对比

    HBase HBase 是 Apache Hadoop 中的一个子项目,属于 bigtable 的开源版本,所实现的语言为Java(故依赖 Java SDK).HBase 依托于 Hadoop 的 H ...

  5. 【bzoj3829】[Poi2014]FarmCraft 贪心

    原文地址:http://www.cnblogs.com/GXZlegend/p/6826667.html 题目描述 In a village called Byteville, there are   ...

  6. POJ 2983-Is the Information Reliable

    Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...

  7. 湘潭邀请赛 2018 E From Tree to Graph

    题意: 给出一棵树以及m,a,b,x0,y0.之后加m条边{(x1,LCA(x1,y1)),(x2,LCA(x2,y2))...(xm,LCA(xm,ym))}.定义z = f(0)^f(1)^... ...

  8. POJ 2074 | 线段相交

    #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #defi ...

  9. BZOJ3668 [Noi2014]起床困难综合症 【贪心】

    题目 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm 一直坚持与起床困难综合症作斗争.通过研究相关文献,他找到了该病的发病原因 ...

  10. 染色 color

    染色 color 题目描述 有一块矩阵平板,分成n*m个格子,一开始全是白色.在这上面进行k次染色,每次染色按照如下步骤:1. 随机选择一个格子,称为A.2. 随机选择一个格子,称为B.3. 将由A ...