zoukankan      html  css  js  c++  java
  • GTW likes math(简单数学)

    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,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].

    Input

    The first line of the input file is an integer TT, indicating the number of test cases. (Tleq 1000T1000)

    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 100a,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][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=3f1​​=3,f2​​=7,f3​​=13,max=13,min=3
    题解:
    就让找[l,r]区间ax ^ 2 + bx + c的最大值和最小值;由于没看到integer domain整数域,用三分和暴力wa了几次;
    代码:
    #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
    ",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
    ",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
    ",m[0],m[1],m[2]);
    		 if(l<=mid&&mid<=r)printf("%.0lf %.0lf
    ",*max_element(m,m+3),*min_element(m,m+3));
    		 else printf("%.0lf %.0lf
    ",max(m[1],m[2]),min(m[1],m[2]));
    	 }
    	return 0;
    }*/
    

      

  • 相关阅读:
    会计日历-自动生成脚本
    Oracle Key Flexfields Qualifiers
    Form Personalization应用总结
    UltraEdit (Ctrl + F) 查找、(Ctrl + R)替换功能失效
    FORM Save : ORA-01403 FRM-40735 ORA-06502
    EBS R12 Vision Profile default value
    EBS增加客制应用CUX:Custom Application
    TortoiseSVN设置比较工具为BeyondCompare
    开源的文件比较工具:WinMerge,KDiff3,diffuse
    C++ Operator Overloading
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5041903.html
Copyright © 2011-2022 走看看