GTW likes math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 942    Accepted Submission(s): 426

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)=ax2+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 T 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, max and min, 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

$f_1=3,f_2=7,f_3=13,max=13,min=3$

 
题意,给你一个方程a*x*x+b*x+c和一个取值范围【l,r】问当x在此区间内取值时,函数的最大值和最小值分别是多少
 
直接暴力求解
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 110
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
int t,Min,Max,i,j;
int a,b,c,l,r,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d%d",&a,&b,&c,&l,&r);
ans=0;Max=-INF;
Min=INF;
if(l>=0) //区间内全是正数
{
for(i=l;i<=r;i++)
{
ans=a*i*i+b*i+c;
Max=max(Max,ans);
Min=min(Min,ans);
}
}
else
{
//printf("%d*\n",abs(l));
if(r>=0) //区间内有负有正
{
for(i=1;i<=abs(l);i++)
{
j=0-i;
//printf("%d*\n",j);
ans=a*j*j+b*j+c;
Max=max(Max,ans);
Min=min(Min,ans);
}
for(i=0;i<=r;i++)
{
ans=a*i*i+b*i+c;
Max=max(Max,ans);
Min=min(Min,ans);
}
}
else//区间内全是负数
{
for(i=abs(r);i<=abs(l);i++)
{
j=0-i;
//printf("%d*\n",j);
ans=a*j*j+b*j+c;
Max=max(Max,ans);
Min=min(Min,ans);
}
}
}
printf("%d %d\n",Max,Min);
}
return 0;
}

  

BestCoder Round #66 (div.2) hdu5592的更多相关文章

  1. 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+ ...

  2. BestCoder Round #66 (div.2)

    构造 1002 GTW likes gt 题意:中文题面 分析:照着题解做的,我们可以倒着做,记一下最大值,如果遇到了修改操作,就把最大值减1,然后判断一下这个人会不会被消灭掉,然后再更新一下最大值. ...

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

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

  4. HDU5596/BestCoder Round #66 (div.2) 二分BIT/贪心

    GTW likes gt    Memory Limit: 131072/131072 K (Java/Others) 问题描述 从前,有nn只萌萌的GT,他们分成了两组在一起玩游戏.他们会排列成一排 ...

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

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

  6. BestCoder Round #66 (div.2) 1002

    GTW likes gt  Accepts: 132  Submissions: 772  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  7. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  8. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

  9. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

随机推荐

  1. UVa 10088 (Pick定理) Trees on My Island

    这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...

  2. 前端SPA框架一些看法

    说起前端框架,我个人主张有框架不如无框架,这个观点要先从框架和库的区别说起. 我所理解的库,解决的是代码或是模块级别的复用或者对复杂度的封装问题;而框架,更多的是对模式级别的复用和对程序组织的规范,这 ...

  3. Androidstudio下Generate signed apk提示Error: Expected resource of type id [ResourceType]解决办法

    只需要在报错位置所在的类上面添加: @SuppressWarnings("ResourceType") 即可实现Generate signed apk.

  4. noip2004提高组题解

    这次有两道题以前已经做过了,所以分数什么的也没有意义了.发现这年的难度设置极不靠谱,前三题都比较简单,最后一题太难,不知道出题人怎么想的. 第一题:储蓄计划 模拟. 第二题:合并果子 贪心.每次选最小 ...

  5. 【C#学习笔记】写文件

    using System; using System.IO; namespace ConsoleApplication { class Program { static void Main(strin ...

  6. LeetCode: Reverse Words in a String && Rotate Array

    Title: Given an input string, reverse the string word by word. For example,Given s = "the sky i ...

  7. 底部菜单栏(二) TabHost & RadioGroup 实现

    需求:使用TabHost & RadioGroup实现底部菜单栏: 效果图: 实现分析: 1.目录结构: 代码实现: 1. activity_main.xml <?xml version ...

  8. UTF-8编码规则

    UTF-8是Unicode的一种实现方式,也就是它的字节结构有特殊要求,所以我们说一个汉字的范围是0X4E00到0x9FA5,是指unicode值,至于放在utf-8的编码里去就是由三个字节来组织,所 ...

  9. Python easy_install

    系统中有高版本的Python, 直接pip3 install ipcalc安装,都是装到高版本的Python 系统默认的Python是2.7.6,现在想装到默认版本中,可以使用easy_install ...

  10. JavaScript 现状:方言篇

    导读 JavaScript 和其他编程语言有一个很大的不同,它不像单纯的一个语言,而像一个由众多方言组成大家族.从 2009 年 CoffeeScript 出现开始,近几年出现了大量基于 JavaSc ...