题意:初始有N颗菜重量分别是w1,...,wn,问你最少切几刀,使得这些菜的最轻和最重的比例符合
思路:师兄做法,考虑到答案说了小于500次,那我们可以用一个优先队列把这些菜记录起来,然后每次选取最重的
菜开始和最轻的比较,如果符合比例就退出来,否则我们就把这个菜i切成++cut[i]份(初始为1),切的
时候是平分,因为切的不均,就会产生大的和小的,会影响结果。所以贪心切。
AC代码:
PS:做法麻烦,仅供参考
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <string.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
const int maxn=5005;
pair<float,float> a[maxn];
float cut[maxn];
int main()
{
float t;
int n;
cin>>t>>n;
for(int i=0; i<n; i++)
{
scanf("%f",&a[i].first);
a[i].second=1;
cut[i]=a[i].first;
}
float*minn,*maxx;
maxx=max_element(cut,cut+n);
minn=min_element(cut,cut+n);
int pos=0;
int ans=0;
while(*minn/(*maxx)<=t)
{
//cout<<*maxx<<' '<<*minn<<' '<<(*minn/(*maxx))<<endl;
pos=maxx-cut;
//cout<<"pos"<<pos<<endl;
int num=++a[pos].second;
*maxx=a[pos].first/num;
maxx=max_element(cut,cut+n);
minn=min_element(cut,cut+n);
ans++;
}
cout<<ans<<endl;
return 0;
}