• GTW likes math(BC 1001)


    GTW likes math

    Accepts: 472
    Submissions: 2140
    Time Limit: 2000/1000 MS (Java/Others)
    Memory Limit: 131072/131072 K (Java/Others)
    问题描述
    某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学《从自主招生到竞赛》。然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你。每一道题目会给
    你一个函数f(x)=ax2+bx+cf(x)=求这个函数在整数区间[l,r]之间的最值。
    输入描述
    第一行一个整数T,表示数据组数。(T≤1000Tleq 1000T1000)
    对于每一组数据,有一行,共五个整数a,b,c,l,r。(∣a∣≤100,∣b∣≤100,∣c∣≤100,∣l∣≤100,∣r∣≤100,l<=r)
    输出描述
    对于每一组数据,共一行两个整数max,min,表示函数在整数区间[l,r][l,r][l,r]中的最大值和最小值。
    
    输入样例
    1
    1 1 1 1 2
    
    输出样例
    7 3
    Hint
    f1=3,f2=7f_1=3,f_2=7f1​​=3,f2​​=7,最大值=7,最小值=3
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 using namespace std;
     5 int a,b,c,l,r;
     6 int func(int x)
     7 {
     8     return x*x*a+b*x+c;
     9 }
    10 int main()
    11 {
    12     int T,i,j;
    13     int x,y;
    14     freopen("in.txt","r",stdin);
    15     cin>>T;
    16     while(T--)
    17     {
    18         scanf("%d %d %d %d %d",&a,&b,&c,&l,&r);
    19         int Min=1000000,Max=-1000000;
    20         if(a==0)
    21         {
    22             Max=max(b*r+c,b*l+c);
    23             Min=min(b*r+c,b*l+c);
    24         }
    25         else
    26         {
    27             for(int i=l;i<=r;i++)
    28             {
    29                 int k=func(i);
    30                 //cout<<k<<endl;
    31                 Max=max(Max,k);
    32                 Min=min(Min,k);
    33             }
    34         }
    35         printf("%d %d
    ",Max,Min);
    36     }
    37 }



  • 相关阅读:
    [CF864F]Cities Excursions
    [AGC012F]Prefix Median
    [TC-FindingFriends]Finding Friends
    [TC-HouseProtection]House Protection
    [CTSC2018]假面
    [CF877F]Ann and Books
    [CF509F]Progress Monitoring
    [CF735E/736C]Ostap and Tree
    CF611H New Year and Forgotten Tree
    CF538H Summer Dichotomy
  • 原文地址:https://www.cnblogs.com/a1225234/p/5041878.html
Copyright © 2020-2023  润新知