zoukankan      html  css  js  c++  java
  • BestCoder Round #66 (div.2) hdu5592

    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. (T1000)

    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*
    ",abs(l));
        		if(r>=0)  //区间内有负有正 
        		{
        			for(i=1;i<=abs(l);i++)
    	    		{
    	    			j=0-i;
    	    			//printf("%d*
    ",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*
    ",j);
    	    			ans=a*j*j+b*j+c;
    	    			Max=max(Max,ans);
    	    			Min=min(Min,ans);
    	    		}
        		}
        	}
        	printf("%d %d
    ",Max,Min);
        }
    	return 0;
    } 
    

      

  • 相关阅读:
    在Linux上使用C语言编程获取IPv4地址及子网掩码
    使用gdb进行写操作
    [中英对照]The Art Of Reporting Bugs | 报bug的艺术
    [中英对照]Introduction to Remote Direct Memory Access (RDMA) | RDMA概述
    Intel万兆网卡背靠背连接ping不通那点事儿
    [中英对照]The sysfs Filesystem | sysfs文件系统
    图说单播,组播,广播,选播和地域播
    Ubuntu双网卡不双待攻略
    反汇编容易反编译难
    PHP之路——微信公众号授权获取用户信息
  • 原文地址:https://www.cnblogs.com/tonghao/p/5231956.html
Copyright © 2011-2022 走看看