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. junit浅学笔记

    JUnit是一个回归测试框架(regression testing framework).Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(Wh ...

  2. th固定 td滚动的表格实现

    为什么这样? 体验好 原理 通过两个表格,使其th td 对应,产生一种错觉. 代码 1.html <div class="content"> <div clas ...

  3. 函数buf_read_page_low

    /********************************************************************//** Low-level function which r ...

  4. ADODB.Connection 错误 '800a0e7a' 未找到提供程序。该程序可能未正确安装。解决方法!

    [问题描述]调试基于ACCESS+ASP的网站程序的时候,遇到如下错误: ADODB.Connection 错误 '800a0e7a' 未找到提供程序.该程序可能未正确安装. /Inc/Functio ...

  5. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

  6. unicode string和ansi string的转换函数及获取程序运行路径的代码

    #pragma once#include <string> namespace stds { class tool { public: std::string ws2s(const std ...

  7. Java [Leetcode 88]CMerge Sorted Array

    题目描述: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. N ...

  8. QuartZ Cron表达式在java定时框架中的应用

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表. CronT ...

  9. Delphi Unable to invoke Code Completion due to errors in source code

    这时因为在.pas文件中存在delphi无法识别的编码,也就是说.pas文件中的字符并非是纯粹的可由文本文件编辑器所能识别的编码.所以,delphi就不可能有效地解释这些编码.因而就出现了自动代码提示 ...

  10. Oracle权限一览表

    权限 所能实现的操作 分析 ANALYZE ANY  分析数据库中的任何表.簇或索引 审计 AUDIT ANY  审计数据库中的任何模式对象 AUDIT SYSTEM  启用与停用语句和特权的审计选项 ...