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,f(x)=ax​2​​+bx+c. Your assignment is to find the maximum value and the

minimum value in the integer domain [l, r][l,r].

Input

The first line of the input file is an integer TT, indicating the number of test cases. (T\leq 1000T≤1000)

In the following TT lines, each line indicates a test case, containing 5 integers, a, b, c, l, ra,b,c,l,r. (|a|, |b|, |c|\leq 100, |l|\leq |r|\leq 100∣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][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=3f​1​​=3,f​2​​=7,f​3​​=13,max=13,min=3

题解:
就让找[l,r]区间ax ^ 2 + bx + c的最大值和最小值;由于没看到integer domain整数域,用三分和暴力wa了几次;
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define T_T while(T--)
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=0x3f3f3f3f;
int a,b,c,l,r;
int js(int x){
return a*x*x+b*x+c;
}
/*void sanfen(double l,double r){
double mx,mi,m,mm;
double x=l,y=r;
while(r-l>=1e-6){
m=(l+r)/2.0;
mm=(m+r)/2.0;
if(js(m)>=js(mm))r=mm;
else l=m;
}
mx=js(l);
l=x;r=y;
while(r-l>=1e-6){
m=(l+r)/2.0;
mm=(m+r)/2.0;
if(js(m)<=js(mm))r=mm;
else l=m;
}
mi=js(l);
printf("%.0lf %.0lf\n",mx,mi);
}*/
int main(){
int T;
SI(T);
int mi,mx;
T_T{
scanf("%d%d%d%d%d",&a,&b,&c,&l,&r);
mi=INF;mx=-INF;
for(int i=l;i<=r;i++){
mi=min(mi,js(i));
mx=max(mx,js(i));
}
printf("%d %d\n",mx,mi);
}
return 0;
}
/*
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define T_T while(T--)
#define mem(x,y) memset(x,y,sizeof(x))
double a,b,c,l,r;
double js(double x){
return a*x*x+b*x+c;
}
int main(){
int T;
SI(T);
T_T{
scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&l,&r);
double mid=-b/(2*a);
double m[3];
m[0]=js(mid);
m[1]=js(l);m[2]=js(r);
//printf("%lf %lf %lf\n",m[0],m[1],m[2]);
if(l<=mid&&mid<=r)printf("%.0lf %.0lf\n",*max_element(m,m+3),*min_element(m,m+3));
else printf("%.0lf %.0lf\n",max(m[1],m[2]),min(m[1],m[2]));
}
return 0;
}*/

  

GTW likes math(简单数学)的更多相关文章

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

    GTW likes math  Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...

  2. GTW likes math(BC 1001)

    GTW likes math Accepts: 472 Submissions: 2140 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 1 ...

  3. Hdu 5595 GTW likes math

    题意: 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主招生到竞赛>.然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你.每一道题 ...

  4. hdu 5595 GTW likes math(暴力枚举查询)

    思路:直接暴力枚举区间[l,r]的整数值,然后max和min就可以了. AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000 ...

  5. JAVA之旅(二十三)——System,RunTime,Date,Calendar,Math的数学运算

    JAVA之旅(二十三)--System,RunTime,Date,Calendar,Math的数学运算 map实在是太难写了,整理得我都晕都转向了,以后看来需要开一个专题来讲这个了,现在我们来时来学习 ...

  6. 简单数学算法demo和窗口跳转,关闭,弹框

     简单数学算法demo和窗口跳转,关闭,弹框demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...

  7. Math concepts / 数学概念

    链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...

  8. HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

    GTW likes function      Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...

  9. HDU 5597 GTW likes function 打表

    GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...

随机推荐

  1. AngularJS ng-class用法

    mark from https://my.oschina.net/gejiawen0913/blog/188547 ng-class是AngularJS预设的一个指令,用于动态自定义dom元素的css ...

  2. A - A

    A - A Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status ...

  3. rsyslog 直接读取日志,当日志截断后,不会继续发送

    rsyslog web机器上日志被截断,那么就不会发送到rsyslog服务器 因为imfile记录了offset,然后你直接>导致offset还没到

  4. Min Stack (LeetCode) tweak it to avoid Memory Limit Exceeded

    class MinStack { public: void push(int x) { if(values.empty()) { values.push_back(x); min_indices.pu ...

  5. 关于oracle spfile配置文件问题

    $ORACLE_SID决定spfile dbs 默认 在启动Oracle数据库时报错,如下: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: R ...

  6. 一步一步学android之控件篇——ScrollView

    一个手机的屏幕大小是有限的,那么我要显示的东西显示不下怎么办?这就会使用到ScrollView来进行滚动显示,他的定义如下: 可以看到ScrollView是继承于FrameLayout的,所以Scro ...

  7. BC第二场

    GT and sequence  Accepts: 385  Submissions: 1467  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  8. 再学习sqlhelper

    在机房收费重构系统的时候,第一次学习sqlhelper.当时感觉比较简单,没有写博客总结,现在又经过了图书馆的学习,感觉还是有必要写一写的. SqlHelper是一个基于.NETFramework的数 ...

  9. 使用Notepad++快速有效删除复制代码中的行号

    转载:http://plum.0602.blog.163.com/blog/static/1130006502011101524120757/ 试了该方法,很好用! 为什么我把用Notepad++删除 ...

  10. JSP——九大内置对象和其四大作用域

    一.JSP九大内置对象: JSP根据Servlet API 规范提供了某些内置对象,开发者不用事先声明就可以使用标准的变量来访问这些对象. Request:代表的是来自客户端的请求,例如我们在FORM ...