GTW likes math

Accepts: 472      Submissions: 2140

 Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others)
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)=ax^2​​+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. (T≤1000)

In the following TT 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, maxmax and minmin, 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

f1=3,f2=7,f3=13,max=13,min=3

问题描述
某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学《从自主招生到竞赛》。然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你。每一道题目会给你一个函数f(x)=ax^2+bx+cf(x)=ax​2​​+bx+c,求这个函数在整数区间[l,r]之间的最值。
输入描述
第一行一个整数T,表示数据组数。(T≤1000)
对于每一组数据,有一行,共五个整数a,b,c,l,r。(∣a∣≤100,∣b∣≤100,∣c∣≤100,∣l∣≤100,∣r∣≤100,l≤r)
输出描述
对于每一组数据,共一行两个整数max,min,表示函数在整数区间[l,r]中的最大值和最小值。
输入样例
1
1 1 1 1 2
输出样例
7 3
Hint
f​1​​=3,f​2​​=7,最大值=7,最小值=3

没必要用什么公式了,一路从L计算到R 保存最大最小就好
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int a,b,c;
int l,r;
int i,j;
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>a>>b>>c>>l>>r;
int maxn=-inf,minn=inf;
for(i=l;i<=r;i++)
{
maxn=max(maxn,a*i*i+b*i+c);
minn=min(minn,a*i*i+b*i+c);
}
cout<<maxn<<" "<<minn<<endl;
}
return 0;
}

  

 

BestCoder Round #66 1001的更多相关文章

  1. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  2. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  3. 暴力 BestCoder Round #46 1001 YJC tricks time

    题目传送门 /* 暴力:模拟枚举每一个时间的度数 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 期末考结束第一 ...

  4. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...

  5. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  6. BestCoder Round #92 1001 Skip the Class —— 字典树 or map容器

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1001 题解: 1.trie树 关 ...

  7. BestCoder Round #66 (div.2)B GTW likes gt

    思路:一个O(n)O(n)的做法.我们发现b_1,b_2,...,b_xb​1​​,b​2​​,...,b​x​​都加11就相当于b_{x+1},b_{x+2},...,b_nb​x+1​​,b​x+ ...

  8. BestCoder Round #61 1001 Numbers

    Problem Description There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,yo ...

  9. BestCoder Round #66 (div.2)

    构造 1002 GTW likes gt 题意:中文题面 分析:照着题解做的,我们可以倒着做,记一下最大值,如果遇到了修改操作,就把最大值减1,然后判断一下这个人会不会被消灭掉,然后再更新一下最大值. ...

随机推荐

  1. 剑指offer 04_替换字符串中的空格

    #include <stdio.h> void ReplaceBlank(char string[],int length){ if(string == NULL || length == ...

  2. Android 数据库 OrmLite Failed to open database

    04-01 16:49:32.720: E/SQLiteLog(1894): (14) cannot open file at line 30204 of [00bb9c9ce4]04-01 16:4 ...

  3. 卸载phonegap

    npm uninstall cordova  -gnpm uninstall phonegap -g

  4. linux磁盘分区fdisk分区和parted分区

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 磁盘分区 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  5. Node内存限制与垃圾回收

    对象分配 所有的JS对象都是通过堆来进行分配的.使用process.memoryUsage()查看使用情况Node.js 中文网文档 process.memoryUsage() { rss: , he ...

  6. IFC数据模型在三维引擎中模拟

  7. 客户注册功能,发短信功能分离 通过ActiveMQ实现

    客户注册功能,发短信功能分离 通过ActiveMQ 配置链接工厂, 配置session缓存工厂(引入链接工厂) 2.配置模板对象JmsTemplate 引入缓存工厂    指定消息模式(队列,发布和订 ...

  8. R: 基本的数学运算

    ################################################### 问题:基本数学运算   18.4.30 R语言用于初等数学的计算,都怎么表示??加减乘除.余数. ...

  9. Servlet入门第二天

    1. GenericServlet: 1). 是一个 Serlvet. 是 Servlet 接口和 ServletConfig 接口的实现类. 但是一个抽象类. 其中的 service 方法为抽象方法 ...

  10. PHP 查看扩展信息的命令

    PHP 查看扩展信息的命令 这里以查看 Swoole 扩展信息为例. root@639ca1f15214:~# php --ri swoole // php --ri [扩展名称] swoole sw ...