HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到

时间:2021-04-11 16:34:59

GTW likes math

 Memory Limit: 131072/131072 K (Java/Others)
问题描述
某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学《从自主招生到竞赛》。然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你。每一道题目会给你一个函数f(x)=ax^2+bx+cf(x)=ax​2​​+bx+c,求这个函数在整数区间[l,r][l,r]之间的最值。
输入描述
第一行一个整数T,表示数据组数。(T\leq 1000T≤1000)
对于每一组数据,有一行,共五个整数a,b,c,l,r。(|a|\leq 100,|b|\leq 100,|c|\leq 100,|l|\leq 100,|r|\leq 100,l\leq r∣a∣≤100,∣b∣≤100,∣c∣≤100,∣l∣≤100,∣r∣≤100,l≤r)
输出描述
对于每一组数据,共一行两个整数max,min,表示函数在整数区间[l,r][l,r]中的最大值和最小值。
输入样例
1
1 1 1 1 2
输出样例
7 3
Hint
f_1=3,f_2=7f​1​​=3,f​2​​=7,最大值=7,最小值=3
//meek///#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N=+;
const int inf = ;
const int mod= ;
int main() { int T,a,b,c,l,r;
scanf("%d",&T);
while(T--) {
int ansl=inf;
int ans=-inf; scanf("%d%d%d%d%d",&a,&b,&c,&l,&r);
for(int i=l;i<=r;i++) {
ans=max(ans,a*i*i+b*i+c);
ansl=min(ansl,a*i*i+b*i+c);
}
cout<<ans<<" "<<ansl<<endl;
}
return ;
}

代码