标签:
It‘s opening night at the opera, and your friend is the prima donna (the lead female singer). You will not be in the audience, but you want to make sure she receives a standing ovation -- with every audience
member standing up and clapping their hands for her.
Initially, the entire audience is seated. Everyone in the audience has a shyness level. An audience member with shyness level Si will wait until at least Si other audience members have already
stood up to clap, and if so, she will immediately stand up and clap. If
You know the shyness level of everyone in the audience, and you are prepared to invite additional friends of the prima donna to be in the audience to ensure that everyone in the crowd stands up and claps in the end. Each of these friends may have any shyness
value that you wish, not necessarily the same. What is the minimum number of friends that you need to invite to guarantee a standing ovation?
The first line of the input gives the number of test cases, T. T test cases follow. Each consists of one line with Smax, the maximum shyness
level of the shyest person in the audience, followed by a string of
The string will never end in a 0. Note that this implies that there will always be at least one person in the audience.
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimum number of friends you must invite.
1 ≤ T ≤ 100.
0 ≤ Smax ≤ 6.
0 ≤ Smax ≤ 1000.
直接从小到大贪心
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<functional> #include<iostream> #include<cmath> #include<cctype> #include<ctime> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define SMAX (1000+10) typedef long long ll; ll mul(ll a,ll b){return (a*b)%F;} ll add(ll a,ll b){return (a+b)%F;} ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;} void upd(ll &a,ll b){a=(a%F+b%F)%F;} int T,smax; char s[SMAX]; int main() { // freopen("A-large.in","r",stdin); // freopen("A-large.out","w",stdout); cin>>T; For(kcase,T) { scanf("%d%s",&smax,s); int n=smax+1; int ans=0,tot=0; Rep(i,n) { if (tot<i) ans+=i-tot,tot=i; tot+=s[i]-'0'; } printf("Case #%d: %d\n",kcase,ans); } return 0; }
GCJ 2015Q(Standing Ovation-贪心)
标签:
原文地址:http://blog.csdn.net/nike0good/article/details/45009919