传送门
题意:
有一群牛,喜欢喝柠檬茶,但是每一只牛,有个特点就是看到队伍前面有A[ ] 头牛它就走了。
农夫不想给太多柠檬茶给牛群,想要最小化。
题解:
简单的贪心题目:排训一下,就是把A[]值大的往前放,后面的看到 前面牛群就走了。
#include<bits/stdc++.h>
using namespace std;
int cmp(int a,int b){
return a>b;
}
int main()
{
int n;
scanf("%d",&n);
int w[100020];
for(int i=0;i<n;i++){
scanf("%d",&w[i]);
}
sort(w,w+n,cmp);
int ans=0;
for(int i=0;i<n;i++){
if(w[i]>=ans){
ans++;
}
}
printf("%d\n",ans);
return 0;
}
本文介绍了一道关于牛群排队喝柠檬茶的算法题目,通过贪心策略解决农夫如何最小化提供柠檬茶的问题。文章给出了C++实现代码。
&spm=1001.2101.3001.5002&articleId=81258053&d=1&t=3&u=3d1961fdfa934aa29c54ae4c6a7f99e0)
461

被折叠的 条评论
为什么被折叠?



