跳到正文

题解

题解:P13211 [GCJ 2015 Qualification] Standing Ovation

goIdie约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年7月13日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
获赞
1
题目
P13211

版本

  1. v1当前

思路

简单贪心。

首先明确一点,为了让站起来鼓掌的人数越多,邀请的朋友的害羞等级肯定要设为 00。即邀请的朋友会立即站起来鼓掌。

我们按害羞程度由低到高处理观众,维护当前站起来鼓掌的人数 tottot。如果 tottot 小于当前观众的害羞程度 ii,就邀请 i−toti-tot 个朋友,然后将 tottot 更新为 ii 并将 tottot 加上害羞程度为 ii 的观众的数量。

时间复杂度 O(Smax)O(S_{max})。

代码

C++
#include<bits/stdc++.h>
using namespace std;
int T,maxs,tot,ans;
string s; 
int main(){
    cin>>T;
    for(int t=1;t<=T;t++){
        cin>>maxs>>s;
        tot=ans=0;
        for(int i=0;i<=maxs;i++){
            if(tot<i){
                ans+=i-tot;
                tot=i;
            }
            tot+=s[i]-'0';
        }

        cout<<"Case #"<<t<<": "<<ans<<endl;
    }
    return 0;
}
原文