CF353D Queue

Jennie

有男有女的情况下光考虑女生就行了。

这个题目有个小规律,对于每一个女生,它的时间是取 $max(上一个女生的时间+1,她前面的男生数量)$。

这是为什么呢,考虑一下什么时候一个女生的时间会受她前一个女生影响。如果俩个女生离得比较近,那么就有可能存在撞车的情况,即前一个女生停住了,导致后一个女生的某一时刻不能移动,浪费了一次移动机会。

那么为什么会是 $+1$ 呢?想一下当后面的女生是不会影响前面的女生撞上了之后。她们就"合为一体"了,后面的人比前面的人有一次移动的延迟,所以后面的人只会比前面的人晚走一次移动 。

这样我们就可以理解这个递推的正确之处了。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
template<class T>inline void read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar('0'+x%10);
}
string s;
int ans;
int la;
int tot;
int main(){
    cin>>s;
    int n=s.length();
    s=' '+s;
    for(int i=1;i<=n;++i){
        if(s[i]=='M'){
            tot++;
        }
        if(s[i]=='F'){
            if(tot){
                ans=max(tot,la+1);
                la=ans;
            }
        }
    }
    cout<<ans;
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇