码迷,mamicode.com
首页 > 其他好文 > 详细

GTW likes math(简单数学)

时间:2015-12-12 23:13:18      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

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)=ax?2??+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. (T\leq 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=3f?1??=3,f?2??=7,f?3??=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\n",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\n",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\n",m[0],m[1],m[2]);
		 if(l<=mid&&mid<=r)printf("%.0lf %.0lf\n",*max_element(m,m+3),*min_element(m,m+3));
		 else printf("%.0lf %.0lf\n",max(m[1],m[2]),min(m[1],m[2]));
	 }
	return 0;
}*/

  

GTW likes math(简单数学)

标签:

原文地址:http://www.cnblogs.com/handsomecui/p/5041903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!