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. fiddler--手机https

    1.访问fiddler的主讲加端口,比如我的是:http://192.168.1.103:8080 在点击fiddlerroot  certificate 下载安装证书即可

  2. (Problem 19)Counting Sundays

    You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...

  3. Linux中的IO复用接口简介(文件监视?)

    I/O复用是Linux中的I/O模型之一.所谓I/O复用,指的是进程预先告诉内核,使得内核一旦发现进程指定的一个或多个I/O条件就绪,就通知进程进行处理,从而不会在单个I/O上导致阻塞. 在Linux ...

  4. Delphi XE的RTTI增强,动态Hook某些内部事件

    Delphi2010之后的RTTI做了很大休整,现在用起来很爽了哦.甚至可以获取某些类的内部私有单元,然后为其赋值!讲这个RTTI增强的,可以参考网上的多个博客内容,我列举一下: Delphi2010 ...

  5. 身份验证cookies和Token

    后端服务器有两种基本的身份验证:1.是基于Cookie的身份验证,使用服务器端的cookie来对每次请求的用户进行身份验证.2. 较新的方法,基于令牌Token的认证,依赖于被发送到服务器上每个请求的 ...

  6. CCNA实验(10) -- Access List

    使用包过滤技术在路由器上读取三层及四层报头的信息如源地址.目的地址.源端口.目的端口根据预先定义好的规则对包进行过滤 三种类型:1.标准ACL:表号范围1-99或1300-1999.仅对源IP地址进行 ...

  7. Codeforces Round#1

    A. Theatre Square 题目大意:有一个长宽为m和n的广场,用边长为a的正方形去铺盖,问铺满最少需要多少正方形 题解:题目分解为用长度为a的线条分别去覆盖长度为m和n的线条,计算两者的乘积 ...

  8. 第七届河南省赛B.海岛争霸(并差集)

    B.海岛争霸 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 130  Solved: 48 [Submit][Status][Web Board] D ...

  9. Paths on a Grid(规律)

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23270   Accepted: 5735 ...

  10. ListBox控件的操作与实现

    .NET FrameWork>參考>类库>System.Windows.Forms>ListBox类的属性 1. 属性列表:     SelectionMode     组件中 ...