hdoj-5595-GTW likes math

Problem Description
After attending the class given by Jin Longyu, who is a specially-graded teacher of Mathematics, GTW started to solve problems in a book titled “From Independent Recruitment to Olympiad”. Nevertheless, there are too many problems in the book yet GTW had a sheer number of things to do, such as dawdling away his time with his young girl. Thus, he asked you to solve these problems.

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] .
 

Input
The first line of the input file is an integer T , indicating the number of test cases. ( T1000 )

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.
 

Output
In each line of the output file, there should be exactly two integers, max and min , indicating the maximum value and the minimum value of the given function in the integer domain [l,r] , respectively, of the test case respectively.
 

Sample Input
   
   
   
   
1 1 1 1 1 3
 

Sample Output
  
  
  
  
13 3
Hint
$f_1=3,f_2=7,f_3=13,max=13,min=3$

就是给你个区间,二次函数,求最大最小值。

数据不大,暴力即可。很简单。读过高中的都知道

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

#define INF 0x7fffffff
#define LL __int64

int a,b,c;

LL fun(double x)
{
    return a*x*x+b*x+c;
}

int main()
{
    int t;
    int low,high;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d%d",&a,&b,&c,&low,&high);
        LL ans1=-INF,ans2=INF;
        for(int i=low;i<=high;i++)
        {
            LL k=fun(i);
            ans1=max(ans1,k);
            ans2=min(ans2,k);
        }
        printf("%I64d %I64d\n",ans1,ans2);
    }
    return 0;
}


你可能感兴趣的:(hdoj-5595-GTW likes math)