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. MySQL在cmd和python下的常用操作

    环境配置1:安装mysql,环境变量添加mysql的bin目录 环境配置2:python安装MySQL-Python 请根据自身操作系统下载安装,否则会报c ++ compile 9.0,import ...

  2. 修改linux内核启动logo及显示位置

    转载于:http://blog.chinaunix.net/uid-28458801-id-3484269.html 在此基础上我又添加了我的一些不同的地方,仅供参考 内核版本: 2.6.35.3 l ...

  3. 《Android应用性能优化》 第8章 图形

    1.例子中 30个部件的xml setContentView 几乎占用了从onCreate() 到 onResume() 结束之前所有时间的99% 因为展开布局的开销很大.要尽量用不同的布局方式.比如 ...

  4. NIO/AIO

    1 NIO NEW IO 的简称,新的java I/O标准,jdk1.4纳入,有以下特点: (1)NIO基于block块,以块(硬盘数据块)为单位处理数据,比旧式的io基于流的效率高. (2)为各个基 ...

  5. SQL IN, NOT IN, EXISTS, NOT EXISTS

    IN与EXISTS执行流程 IN:在查询的时候,首先查询子查询的表,然后将内表和外表做一个笛卡尔积,然后按照条件进行筛选.所以相对内表比较小的时候,in的速度较快.(IN时不对NULL进行处理) EX ...

  6. C++获取电脑上连接的多个摄像头名称与编号

    #include<iostream>#include "strmif.h"#include <initguid.h>#include<vector&g ...

  7. 在Linux里安装jdk

    一.系统环境说明: [操作系统]:Ubuntu 18.04.1 Desktop [JDK]:jdk1.8.0_181,文件名称:jdk-8u181-linux-x64.tar 二.准备jdk文件 下载 ...

  8. Entity Framework Tutorial Basics(1):Introduction

    以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...

  9. nstallShield制作打包程序详解(图)

    InstallShield产品,是安装工具领域事实上的标准.InstallShield 软件是软件安装.配置软件包和升级解决方案领域内公认的标准.InstallShield已经成为安全安装软件的标准解 ...

  10. C# 抽象方法及抽象类 Abstract 及接口

    public abstract class Animal { public abstract void Dosth(); } 该类中只有虚方法  那么我们可以用abstract来修饰  将该类称为抽象 ...