链接:

http://acm.hdu.edu.cn/showproblem.php?pid=2899

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4802    Accepted Submission(s): 3427

Problem Description
Now, 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.
 
Input
The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)
 
Output
Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
 
Sample Input
2
100
200
 
Sample Output
-74.4291
-178.8534
 
F'(x) = 42 * x^6+48*x^5+21*x^2+10*x-y
 
42 * x^6+48*x^5+21*x^2+10*x = y
x 要是 double 类型的, 左边要尽可能接近右边的 y 值
再带入F(x)中
F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x

代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5.  
  6. #define N 150
  7. #define D (1e-6)
  8.  
  9. double f(double x)
  10. {
  11. return *pow(x, 6.0) + *pow(x, 5.0) + *pow(x, 2.0) + *x;
  12. }
  13.  
  14. double F(double x)
  15. {
  16. return *pow(x, 7.0) + *pow(x, 6.0) + *pow(x, 3.0) + *pow(x, 2.0);
  17. }
  18.  
  19. int main()
  20. {
  21.  
  22. int t;
  23. scanf("%d", &t);
  24.  
  25. while(t--)
  26. {
  27. int y;
  28.  
  29. scanf("%d", &y);
  30.  
  31. if(y>=f())
  32. printf("%.4f\n", F()-*y);
  33. else
  34. {
  35.  
  36. double L=, R=, m;
  37.  
  38. while(R-L>D)
  39. {
  40. m = (L+R)/;
  41. if(f(m)<=y) L=m;
  42. else R=m;
  43. }
  44.  
  45. printf("%.4f\n", F(L)-L*y);
  46. }
  47. }
  48. return ;
  49. }

(二分搜索 )Strange fuction -- HDU -- 2899的更多相关文章

  1. Strange fuction hdu 2899

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. hdu 2899 Strange fuction

    http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...

  3. ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  4. hdu 2899 Strange fuction (二分法)

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. hdoj 2899 Strange fuction【二分求解方程】

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. 【精度问题】【HDU2899】Strange fuction

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. Strange fuction

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  8. HDU2899 Strange fuction 【二分】

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 2899 Strange fuction (二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899 题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x ( ...

随机推荐

  1. [C++ Primer] 第3章: 字符串, 向量和数组

    标准库类型string string初始化 string s2(s1); string s2 = s1; string s3("value"); string s3 = " ...

  2. rabbitMQ应用,laravel生产广播消息,springboot消费消息

    最近做一个新需求,用户发布了动态,前台需要查询,为了用户读取信息响应速度更快(MySQL很难实现或者说实现起来很慢),所以在用户动态发布成功后,利用消息机制异步构建 redis缓存 和 elastic ...

  3. Form中的keypress事件不能用

    Form中的keypress事件不能用 编写人:CC阿爸 2015-4-8 近期在修改系统时,想给一画面增加一个组合键功能,但在form_keypress事件中加入代码,但无论如何也不能触发该动作. ...

  4. 善待Erlang 代码 -- Xref 实践

    Xref 是一个交叉引用工具,通过分析定义的函数间的调用关系,用于查找函数. 模块. 应用程序和版本之间的依赖关系. 通俗而言,Xref 可以检查代码中函数的调用关系.比如在 moduleA 中的 f ...

  5. 微信小程序获取用户openid,头像昵称信息,后台java代码

    https://blog.csdn.net/qq_39851704/article/details/79025557

  6. 汇编_指令_SUB

    SUB是减法运算. 比如mov ax,2mov bx,1sub ax,bx 其中sub ax,bx就是ax中的值减bx中的值,等于1,然后把结果,也就是1,放入ax中.

  7. undefined和NAN的区别(转)

    Javascript 中 null.NaN和undefined的区别 1.类型分析: js中的数据类型有undefined,boolean,number,string,object等5种,前4种为原始 ...

  8. javascript的创建对象object.create()和属性检测hasOwnPrototype()和propertyIsEnumerable()

    Object.create("参数1[,参数2]")是E5中提出的一种新的对象的创建方式. 第一个参数是要继承到新对象原型上的对象; 第二个参数是对象属性.这个参数可选,默认为fa ...

  9. 阿里云短信接口python版本

    # -*- coding: utf-8 -*- #!/usr/bin/python #encoding=utf-8 import sys from aliyunsdkdysmsapi.request. ...

  10. 公共文件模块include

    首先新建一个include 把所有引入的文件放入公共文件里 function getBaseURL() { var pathName = window.document.location.pathna ...