感觉要优化空间
查看原帖
感觉要优化空间
349798
BensonQAQ666楼主2021/10/6 16:26

啊RE了,数组大了也一样

代码

#include<iostream>
using namespace std;
int n,m,a,b,c,k,l,now,h[10000001];
void p(int x)
{
	h[++l]=x;
	now=l;
	while(now!=1&&h[now]<h[now/2])
	{
		swap(h[now],h[now/2]);
		now/=2;
	}
}
void g()
{
	h[1]=h[l--];
	now=1;
	while(now*2<=l&&h[now]>min(h[now*2],h[now*2+1]))
	{
		if(h[now*2]>h[now*2+1])
		{
			swap(h[now],h[now*2+1]);
			now*=2;
			now++;
		}
		else
		{
			swap(h[now],h[now*2]);
			now*=2;
		}
	}
}
int main()
{
	int i,j,k;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		for(j=1;j<=m;j++)
		{
			k=a*j*j+b*j+c;
			p(k);
		}
	}
	for(i=1;i<=m;i++)
	{
		cout<<h[1]<<" ";
		g();
	}
	return 0;
}
2021/10/6 16:26
加载中...