P2085 Minimum function value (minval
)Title Description
There are n functions, F1,f2,..., Fn, respectively. Defines fi (x) =ai*x^2+bi*x+ci (x∈n*). Given these AI, Bi, and CI, request the smallest m of all function values of all functions (if there are duplicates to output multiple).
Input/output format
Input format:
Input data: The first line enters two positive integers n and M. The following n rows are three positive integers per line, where the three digits of line I are AI, bi, and CI respectively. Ai<=10,bi<=100,ci<=10 000.
Output format:
Output data: The output sorts the first m elements of all the function values that can be generated by these n functions. The m number should be output to one line, separated by a space.
Input/Output sampleInput Sample # #:
3 104 5 33 4 51 7 1
Sample # # of output:
9 12 12 19 25 29 31 44 45 54
Description
Data size: n,m<=10000
/*Save the current minimum m function value with a priority queue Q. Because a,b,c>0, so f (x) is the increment function. So this m value must be obtained in X=1,2,3...M. First, the first m values of a function are pressed into the queue. For the 2nd, 3, 4......N functions, X is traversed 1 to m at a time. If f (x) is greater than or equal to the top of the heap, then the function values of x and X are larger than this m large and can be broken directly without calculation. Otherwise, the top of the heap pops up and F (x) is pressed into the queue. */#include<cstdio>#include<queue>using namespaceStd;priority_queue<int>Q;intans[10005],n,m,a,b,c,x;intMain () {scanf ("%d%d",&n,&m); scanf ("%d%d%d",&a,&b,&c); for(intI=1; i<=m;++i) Q.push (a*i*i+b*i+c); while(--N) {scanf ("%d%d%d",&a,&b,&c); for(intI=1; i<=m;++i) {x=i*i*a+i*b+B; if(X>=q.top ()) Break; ElseQ.pop (), Q.push (x); } } for(intI=m;i;--i) ans[i]=q.top (), Q.pop (); for(intI=1; i<=m;++i) printf ("%d", Ans[i]); return 0;}
If the heart is sunny, no words sorrow
P2085 Minimum function value (priority queue)