思路
简单贪心。
首先明确一点,为了让站起来鼓掌的人数越多,邀请的朋友的害羞等级肯定要设为 。即邀请的朋友会立即站起来鼓掌。
我们按害羞程度由低到高处理观众,维护当前站起来鼓掌的人数 。如果 小于当前观众的害羞程度 ,就邀请 个朋友,然后将 更新为 并将 加上害羞程度为 的观众的数量。
时间复杂度 。
代码
#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;
}