GTW likes Math accepts:472 submissions:2140Time limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)Problem Description
After attending the class given by Jin Longyu, who was a specially-graded teacher of mathematics, GTW started to solve prob Lems in a book titled "From Independent Recruitment to Olympiad". Nevertheless, there is too many problems in the book yet GTW had a sheer number of things to do, such as dawdling away hi s time with He young girl. Thus, he asked you to solve these problems.
In each problem, you'll be given a function whose form are like f (x) =ax ^ 2 + bx + C,f (x) = ax? 2+bx+ c. Your assignment is to find the maximum value and the
< Span class= "Vlist" > minimum value in the integer domain [l, R][l< Span class= "mpunct" >,r].
Input
The first line of the input file was an integer tT, indicating the number of test cases. (t\leqT≤1000)
In the followingTTLines, each line indicates a test case, containing 5 integers,A, B, C, L, RA,B,C,L,R. (|a|, |b|, |c|\leq, |l|\leq |r|\leq 100∣A∣,∣b∣,∣c∣≤100,∣l∣ ≤∣r∣≤100), whose meanings is given above.
Output
In all line of the output file, there should is exactly the integers,MaxMAx and minm in, indicating the maximum value and the minimum value of the given FU Nction in the integer domain [l, R][l,r
Sample Input
11 1 1) 1 3
Sample Output
13 3
HintF_1=3,f_2=7,f_3=13,max=13,min=3F?1??=3,F?2?? =7,f< Span class= "Vlist" >? 3?? =13,m< Span class= "Mord mathit" >ax=1 3,min=3 < Span class= "Mord" > < Span class= "Mord" > Puzzle: < Span class= "Reset-textstyle scriptstyle cramped" > < Span class= "Mord" >< Span class= "Mord mathit" > Let's find [l,r] Interval ax ^ 2 + bx + C for maximum and minimum; because you don't see an integer domain , with three points and violent wa a few times; < Span class= "Mord" > < Span class= "Mord" > Code:
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include < algorithm> #include <queue> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define P_ printf ("") #define T_T while (t--) #define MEM (x, y) memset (x, Y, sizeof (x)) const int Maxn=0x3f3f3f3f;int a,b,c,l,r;int JS (int x) {return a*x*x+b*x+c;} /*void Sanfen (double l,double r) {double mx,mi,m,mm;double x=l,y=r;while (r-l>=1e-6) {m= (l+r)/2.0;mm= (m+r)/2.0;if ( JS (m) >=js (mm)) R=mm;else l=m;} Mx=js (l); L=x;r=y;while (r-l>=1e-6) {m= (l+r)/2.0;mm= (m+r)/2.0;if (JS (m) <=js (mm)) R=mm;else l=m;} Mi=js (L);p rintf ("%.0lf%.0lf\n", Mx,mi);} */int Main () {int T; SI (T); int mi,mx; t_t{scanf ("%d%d%d%d%d", &a,&b,&c,&l,&r); mi=inf;mx=-inf; for (int i=l;i<=r;i++) {mi=min (mi,js (i)); Mx=max (Mx,js (i)); } printf ("%d%d\n", mx,mi); }return 0;} /* #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include <queue> #include <vector>using namespace Std;const int inf= 0x3f3f3f3f; #define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define P_ printf ("") #define T_T while (t--) # Define MEM (x, y) memset (x,y,sizeof (x)) Double a,b,c,l,r;double js (double x) {return a*x*x+b*x+c;} int main () {int T; SI (T); t_t{scanf ("%lf%lf%lf%lf%lf", &a,&b,&c,&l,&r); double mid=-b/(2*a); double m[3]; M[0]=js (mid); m[1 ]=js (l); M[2]=js (R); printf ("%lf%lf%lf\n", m[0],m[1],m[2]); if (l<=mid&&mid<=r) printf ("%.0lf%.0lf\n", *max_element (m,m+3), *min_element (m,m+3)); else printf ("%.0lf%.0lf\n", Max (m[1],m[2]), Min (m[1],m[2])); }return 0;} */
GTW likes math (simple math)