题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26476

  题意:给一个字符序列,比如MWMMW,每次可以取前面两个中的一个,取出来后,取出来的那个个数加一,要求使得两个字符的个数不超过n,求最多能取多少个。。

  贪心就可以了。

 //STATUS:C++_AC_36MS_1480KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
//#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=1e9+,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int n,vis[N],ans;
char s[N];
int main(){
// freopen("in.txt","r",stdin);
int i,j,l,r;
while(~scanf("%d",&n))
{
scanf("%s",s); mem(vis,);
int len=strlen(s);
int cntm,cntw;
cntm=cntw=ans=;
for(i=;i<len;i++){
l=r=-;
for(j=;j<len;j++){
if(!vis[j]){
if(l==-)l=j;
else {r=j;break;}
}
}
if(cntm<=cntw){
if(s[l]=='M')cntm++,vis[l]=;
else if(s[r]=='M')cntm++,vis[r]=;
else cntw++,vis[l]=;
}
else {
if(s[l]=='W')cntw++,vis[l]=;
else if(s[r]=='W')cntw++,vis[r]=;
else cntm++,vis[l]=;
}
if(abs(cntm-cntw)>n)break;
ans++;
} printf("%d\n",ans);
}
return ;
}

BNUOJ-26476 Doorman 贪心的更多相关文章

  1. Aizu 2456 Usoperanto 贪心 拓扑排序

    Usoperanto Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.bnuoj.com/v3/contest_show.php?cid= ...

  2. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  3. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  8. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  9. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

随机推荐

  1. Samza文档翻译 : Concepts

    此页介绍啊Samza的一些高层级概念. Streams Samza处理Streams(流).流由同一类型的不可变的消息组成.例如,一个流可以是对一个网站的所有点击,或者对一个数据库表的所有更新,或者一 ...

  2. 解决ubuntu中vi不能正常使用方向键与退格键的问题

    方案一: 问题: ubuntu中vi在编辑状态下方向键不能用,还有回格键不能删除等我们平时习惯的一些键都不能使用. 解决办法: 可以安装vim full版本,在full版本下键盘正常,安装好后同样使用 ...

  3. Java中的try、catch、finally块简单的解析

    package com.wangzhu; import java.util.HashMap; import java.util.Map; /** * 在try.catch.finally块中,若try ...

  4. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-007-给flowl加权限控制<secured>

    States, transitions, and entire flows can be secured in Spring Web Flow by using the <secured> ...

  5. WPF中映射clr namspace

    1. xaml中直接映射为prefix xmlns:prefix="clr-namespace:MyApplication.Modules.Entity;assembly=MyAssembl ...

  6. C/C++中static关键词的作用

    1.在函数体内的static变量作用范围是该函数体,其只被内存分配一次,所以在下次调用的时候会保持上一次的值. 2.模块内的static全局变量可以被模块内的所有函数访问,但不能被模块外的函数访问. ...

  7. 两个STL网址 总结的很好 && c++堆的网址

    http://www.cnblogs.com/bigcat814/ http://blog.sina.com.cn/s/blog_7065a9de010154ve.html 堆 http://www. ...

  8. Thread: BooleanRT : Realtime 3D boolean operations for (Runtime,Editor)

    A Product by Mixed Dimensions What is BooleanRT? BooleanRT is a real-time 3D boolean operations exte ...

  9. POJ 2318 (叉积) TOYS

    题意: 有一个长方形,里面从左到右有n条线段,将矩形分成n+1个格子,编号从左到右为0~n. 端点分别在矩形的上下两条边上,这n条线段互不相交. 现在已知m个点,统计每个格子中点的个数. 分析: 用叉 ...

  10. ZOJ 2760 How Many Shortest Path (不相交的最短路径个数)

    [题意]给定一个N(N<=100)个节点的有向图,求不相交的最短路径个数(两条路径没有公共边). [思路]先用Floyd求出最短路,把最短路上的边加到网络流中,这样就保证了从s->t的一个 ...