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 ...
随机推荐
- C++_知识点_指针类型转换
#include <iostream> using namespace std; int main(){ ] = {, , , , , , , , , }; int* p = (int*) ...
- 论try/catch的重要性,我们经常遇到代码出现无法调试的错误,程序退出的时候崩溃。这跟我们代码日常保护的习惯息息相关。
每当构造函数或析构函数中出现溢出,会导致调试非常困难,而使用try/catch来处理构造中的初始化就非常重要了. 如上图,在构造函数中,我们的很多初始化动作会放在这里,但是却忽视了,一旦初始化出错了, ...
- hadoop hdfs 一些命令记录
1.列出目录下的对象:hadoop fs -ls /lib 2.统计文件行数:hadoop fs -cat /文件* | wc -l 3.统计文件或者目录大小:hadoop fs -count /l ...
- codeforces 630P. Area of a Star
题目链接 圆上n个点等距离分布, 求构成的星星的面积. 我们可以求三角形OAB的面积, ∠CAE = 1/2 ∠ COE = PI/n, 那么∠CAO = PI/2n, ∠AOB非常好求, 就是PI/ ...
- Visual Studio 常用快捷键总结
删除或剪切一行: Ctrl + X 或者 Shift+Delete格式化整个文档: Ctrl + K + D 或者 Ctrl+E+D智能感知: Ctrl + J 或者 Alt+→折叠所有方法: C ...
- ACPI引起linux系统无故重启
新装机器无故重启多次. centos6 64bit uname -a Linux Eos 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 201 ...
- Android Material Design 之 Toolbar的使用
Material Design是谷歌提出来的最新ui设计规范,我想actionbar大家也许并不陌生,toolbar简单而言可以看做为actionbar的升级版,相比较actionbar而言,tool ...
- 自己模拟实现math.h中的函数
之前一直都很迷惑pow()函数时怎么实现的,对于整数次的幂我还能很容易做到,但是对于分数次幂就不是那么好做了.需要一些高等数学级数的知识. 我这里实现了求ln(x), pow(double x, do ...
- php 配置文件
<?php return array( 'TMPL_L_DELIM'=>'<{', //配置左定界符 'TMPL_R_DELIM'=>'}>', //配置右定界符 'DB ...
- Linux-NGINX 能否添加P3P头,如何添加。 - 德问:编程社交问答
Linux-NGINX 能否添加P3P头,如何添加. - 德问:编程社交问答 您的投票让 杜鑫 声誉值增加5分. 支持投票,不仅能让提问用户获得声誉值,让好的问题有更多的曝光,更能帮助社区筛选出好 ...