GTW likes math
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 498 Accepted Submission(s): 254
In each problem, you will be given a function whose form is like f(x)=ax2+bx+c. Your assignment is to find the maximum value and the minimum value in the integer domain [l,r].
In the following T lines, each line indicates a test case, containing 5 integers, a,b,c,l,r. (|a|,|b|,|c|≤100,|l|≤|r|≤100), whose meanings are given above.
出題人:由於是整數區間,直接枚舉即可。時間複雜度O(T∗(r−l))
#include
#include
using namespace std;
int a[8];
int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
for(int i=0; i<5; i++)
{
scanf("%d",&a[i]);
}
int mixn=99999999,maxn=-99999999;
for(int i=a[3]; i<=a[4]; i++)
{
int kk=a[0]*i*i+a[1]*i+a[2];
if(kkmaxn)maxn=kk;
}
printf("%d %d\n",maxn,mixn);
}
return 0;
}