Strange fuction HDU 2899 "two minutes"

Source: Internet
Author: User

Problem Descriptionnow, here is a fuction:
F (x) = 6 * X^7+8*X^6+7*X^3+5*X^2-Y*X (0 <= x <=100)
Can you find the minimum value when x is between 0 and 100.
Inputthe first line of the input contains an integer T (1<=t<=100) which means the number of test cases. Then T-lines follow, each of the line have only one real numbers y. (0 < y <1e10)
Outputjust the minimum value (accurate up to 4 decimal places) while X is between 0 and 100.
Sample Input
2100200

Sample Output
-74.4291-178.8534


#include <stdio.h> #include <math.h>int y;double fun1 (double x) {    return 42*pow (x,6) + 48*pow (x,5) + 21*x* x + 10*x-y;} Double fun2 (double x) {    return 6*pow (x,7) + 8*pow (x,6) + 7*x*x*x + 5*x*x-y*x;} int main () {    int T;    scanf ("%d", &t);    while (t--)    {        scanf ("%d", &y);        Double Left=0,right=100,middle;        while (right-left>=1e-10)        {            middle= (left+right)/2;            if (fun1 (middle) >0) Right=middle;            else left=middle;        }        printf ("%.4lf\n", fun2 (left));    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Strange fuction HDU 2899 "two minutes"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.