题解:P13211 [GCJ 2015 Qualification] Standing Ovation
思路
简单贪心。
首先明确一点,为了让站起来鼓掌的人数越多,邀请的朋友的害羞等级肯定要设为
我们按害羞程度由低到高处理观众,维护当前站起来鼓掌的人数
时间复杂度
代码
#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;
}