题解:P13312 [GCJ 2012 Qualification] Dancing With the Googlers
题意
给出 Googler 的人数
思路
看到最多,想到贪心。
贪心方法:
逐个枚举,若这个 Googler 的总分能达到
贪心证明
若这个 Googler 的总分能达到
若这个 Googler 的总分能达到
若这个 Googler 的总分不能达到
代码
易错点:当
#include<bits/stdc++.h>
using namespace std;
int t,s,p,n,a[100001];
int main(){
cin>>t;
for(int k=1;k<=t;k++){
memset(a,0,sizeof(int));
long long ans=0;
cin>>n>>s>>p;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++){
if(a[i]>=p+p+p-2)//若这个 Googler 的总分能达到 3*p-2
ans++;
else if(a[i]>=max(p+p+p-4,1)&&s>0){//若这个 Googler 的总分能达到 3*p-4 且 s>0
ans++;
s--;
}
}
cout<<"Case #"<<k<<": "<<ans<<endl;
}
}
这题真是黄题吗?