zoukankan      html  css  js  c++  java
  • BestCoder Round #66 1001

    GTW likes math 

    Accepts: 472      Submissions: 2140    
     Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others)
    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)=ax^2​​+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. (T1000)

    In the following TT lines, each line indicates a test case, containing 5 integers, a, b, c, l, r. (a,b,c100,lr100), whose meanings are given above.

    Output

    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], respectively, of the test case respectively.

    Sample Input
    1
    1 1 1 1 3
    Sample Output
    13 3
    Hint
    f1=3,f2=7,f3=13,max=13,min=3
    问题描述
    某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学《从自主招生到竞赛》。然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你。每一道题目会给你一个函数f(x)=ax^2+bx+cf(x)=ax2​​+bx+c,求这个函数在整数区间[l,r]之间的最值。
    输入描述
    第一行一个整数T,表示数据组数。(T1000)
    对于每一组数据,有一行,共五个整数a,b,c,l,r。(a100,b100,c100,l100,r100,lr)
    输出描述
    对于每一组数据,共一行两个整数max,min,表示函数在整数区间[l,r]中的最大值和最小值。
    
    输入样例
    1
    1 1 1 1 2
    
    输出样例
    7 3
    Hint
    f1​​=3,f2​​=7,最大值=7,最小值=3

    没必要用什么公式了,一路从L计算到R 保存最大最小就好
    #include<stdio.h>
    //#include<bits/stdc++.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<queue>
    #include<map>
    #include<vector>
    #include<algorithm>
    #include<limits.h>
    #define inf 0x3fffffff
    #define INF 0x3f3f3f3f
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define ULL unsigned long long
    using namespace std;
    int a,b,c;
    int l,r;
    int i,j;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            cin>>a>>b>>c>>l>>r;
            int maxn=-inf,minn=inf;
            for(i=l;i<=r;i++)
            {
                maxn=max(maxn,a*i*i+b*i+c);
                minn=min(minn,a*i*i+b*i+c);
            }
            cout<<maxn<<" "<<minn<<endl;
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    高德离线地图瓦片坐标偏移纠偏
    CefSharp禁止弹出新窗体,在同一窗口打开链接,或者在新Tab页打开链接,并且支持带type="POST" target="_blank"的链接
    C# .NET的BinaryFormatter、protobuf-net、Newtonsoft.Json以及自己写的序列化方法序列化效率和序列化后的文件体积大小对比
    C# Task 多任务 限制Task并发数量
    C# List 根据对象属性去重的四种方法对比
    WPF使用FlowDocument实现图文混排
    C# List与Dictionary相互转换与高效查找
    Windows服务安装批处理命令
    C# 32位程序 申请大内存
    代码的鲁棒性:链表中倒数第k个结点
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5043935.html
Copyright © 2011-2022 走看看