Hdoj 2899 Strange fuction

Source: Internet
Author: User

Strange fuctionTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 4795 Accepted Submission (s): 3420

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 Simple binary + Mathematics: two points after derivation to find the closest value to Y, at this time the original function is the smallest;
#include <stdio.h> #include <math.h>double y;double Hanshu (double x)//original function value {return 6*pow (x,7) +8*pow (x,6) +7 *pow (x,3) +5*pow (x,2)-y*x;} Double Daoshu (double x)//Guide Value {return 42*pow (x,6) +48*pow (x,5) +21*pow (x,2) +10*x-y;} int main () {int n;scanf ("%d", &n), while (n--) {scanf ("%lf", &y), if (Y>=daoshu ()) printf ("%lf\n", Hanshu ( );d ouble Right =100,left=0;while ((right-left) >=1e-10)//dichotomy {double mid= (right+left)/2;if (Daoshu (mid) >0) Right=mid;elseleft=mid;} printf ("%.4lf\n", Hanshu (right));} return 0;}





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

Hdoj 2899 Strange fuction

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.