Cows drying clothes (greedy)

Cows drying clothes

Insert picture description here

Problem solving ideas

Greedy thinking
first of all enter the number of the priority queue (that is, the first team maximum queue)
and then let the head of the queue using the dryer ( dryer can dry naturally and work together )
and finally make it into the team
until dry up

AC code

#include<cstdio>
#include<queue>
using namespace std;
int n,a,b,h,time,head;
priority_queue<int>f;//优先队列
int main()
{
    
    
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
    
    
	 	scanf("%d",&h);
		f.push(h);//入队
	}
	while(f.top()>time*a)//队首与正常晾干比较
	{
    
    
		time++;//时间+1
		head=f.top();//赋值
		f.pop();//弹出
		f.push(head-b);//入队
	}
	printf("%d",time);
	return 0;
}

Thank you

Guess you like

Origin blog.csdn.net/weixin_45524309/article/details/111994237
Recommended