链接:

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

代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h> #define N 150
#define D (1e-6) double f(double x)
{
return *pow(x, 6.0) + *pow(x, 5.0) + *pow(x, 2.0) + *x;
} double F(double x)
{
return *pow(x, 7.0) + *pow(x, 6.0) + *pow(x, 3.0) + *pow(x, 2.0);
} int main()
{ int t;
scanf("%d", &t); while(t--)
{
int y; scanf("%d", &y); if(y>=f())
printf("%.4f\n", F()-*y);
else
{ double L=, R=, m; while(R-L>D)
{
m = (L+R)/;
if(f(m)<=y) L=m;
else R=m;
} printf("%.4f\n", F(L)-L*y);
}
}
return ;
}

(二分搜索 )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. RK3288 双屏异显,两屏默认方向不一致

    CPU:RK3288 系统:Android 5.1 RK3288 支持双屏异显,一般都会同方向显示,如果遇到两个 lcd 的默认方向不一致,只需修改下面参数即可. 例如:主屏为mipi接口,分辨率为 ...

  2. 对类 sizeof

    sizeof一个类的时候,都什么会被计算?静态成员会被计算进来么?如果这是一个子类,它的父类成员会被计算么? #include <iostream> using namespace std ...

  3. TS流解析 一

    一 从TS流开始 数字电视机顶盒接收到的是一段段的码流,我们称之为TS(Transport Stream,传输流),每个TS流都携带一些信息,如Video.Audio以及我们需要学习的PAT.PMT等 ...

  4. NPOI-Excel系列-1002.创建带有Document Summary Information和Summary Information的Excel文件

    1. using NPOI.HSSF.UserModel; using NPOI.HPSF; using NPOI.POIFS.FileSystem; using Microsoft.VisualSt ...

  5. 二、jdk命令之javah命令(C Header and Stub File Generator)

    目录 一.jdk工具之jps(JVM Process Status Tools)命令使用 二.jdk命令之javah命令(C Header and Stub File Generator) 三.jdk ...

  6. todolist_高级写法

    <!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" conten ...

  7. linux centos 6.1 安装 redis

    1, yum install redis 检测是否有redis 2,没有的话就运行:yum install epel-release 3,再执行 yum install redis

  8. Java遍历一个目录下的所有文件

    Java遍历一个目录下的所有文件   Java工具中为我们提供了一个用于管理文件系统的类,这个类就是File类,File类与其他流类不同的是,流类关心的是文件的内容,而File类关心的是磁盘上文件的存 ...

  9. delphi TEncoding

    #include <tchar.h> #include <memory> //For STL auto_ptr class //------------------------ ...

  10. Redis 哨兵模式 带密码单机

    语法 https://segmentfault.com/a/1190000002680804 启动3台redis 6379,6380,6381 cp 多个redis.conf文件 开启daemoniz ...