GTW likes math(简单数学)
GTW likes math
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)=ax2+bx+c. Your assignment is to find the maximum value and the
minimum value in the integer domain [l, r][l,r].
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.
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.
1
1 1 1 1 3
13 3
f_1=3,f_2=7,f_3=13,max=13,min=3f1=3,f2=7,f3=13,max=13,min=3
#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(简单数学)的更多相关文章
- HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到
GTW likes math Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...
- GTW likes math(BC 1001)
GTW likes math Accepts: 472 Submissions: 2140 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 1 ...
- Hdu 5595 GTW likes math
题意: 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主招生到竞赛>.然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你.每一道题 ...
- hdu 5595 GTW likes math(暴力枚举查询)
思路:直接暴力枚举区间[l,r]的整数值,然后max和min就可以了. AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000 ...
- JAVA之旅(二十三)——System,RunTime,Date,Calendar,Math的数学运算
JAVA之旅(二十三)--System,RunTime,Date,Calendar,Math的数学运算 map实在是太难写了,整理得我都晕都转向了,以后看来需要开一个专题来讲这个了,现在我们来时来学习 ...
- 简单数学算法demo和窗口跳转,关闭,弹框
简单数学算法demo和窗口跳转,关闭,弹框demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...
- Math concepts / 数学概念
链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...
- HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数
GTW likes function Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...
- HDU 5597 GTW likes function 打表
GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...
随机推荐
- 在sqlite中使用索引
出处: 网络 1)Sqlite不支持聚集索引,android默认需要一个_id字段,这保证了你插入的数据会按“_id”的整数顺序插入,这个integer类型的主键就会扮演和聚集索引一样的角色.所以不要 ...
- this .运算符 和 [] 运算符
首先看这个 这两个运行结果是不一样的 前两个是3 后面是10 var length = 10; var arr = [function(){console.log(this.length);},2 ...
- 转: JS自定义事件的定义和触发(createEvent, dispatchEvent)
四.伪DOM自定义事件 这里的“伪DOM自定义事件”是自己定义的一个名词,用来区分DOM自定义事件的.例如jQuery库,其是基于包装器(一个包含DOM元素的中间层)扩展事件的,既与DOM相关,又不直 ...
- 电脑Win7如何取得文件管理所有权(提供各种GHOST版本的Windows)
电脑Windows7系统如何取得文件管理所有权?从 VISTA开始,微软对操作系统的安全性有了明显的提高,这样使得以前我们在XP下都可以打开或删除的文件(夹),无法在WIN7下进行操作.就算是在 Ad ...
- LRU算法的设计
一道LeetCode OJ上的题目,要求设计一个LRU(Least Recently Used)算法,题目描述如下: Design and implement a data structure for ...
- Finding the Longest Palindromic Substring in Linear Time
Finding the Longest Palindromic Substring in Linear Time Finding the Longest Palindromic Substring i ...
- C#获取时间的函数
//获取日期+时间DateTime.Now.ToString(); // 2012-9-4 20:02:10DateTime.Now.ToLocalTime().ToString ...
- IIS网站发布容易出现的几个问题
1. 更新版本或者重新安装.net Framework: 2. 更改配置文件节点: 3. 访问权限问题的更改:
- 【Web】十步教你搭建完整免费的个人网站(花生壳+XAMPP+WordPress)
1.从花生壳官网(http://www.oray.com/peanuthull/download.php)下载最新版本的客户端. 下载完成后安装,注册护照(需手机验证码验证),注册完成后获取免费域名并 ...
- 关于php支持的协议与封装协议
<?php /* * php://stdin 标准输入流 * php://stdout 标准输入流 * php://stderr 标准错误流 * php://output 只写的数据流 * ph ...