Strange fuction

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

Total Submission(s): 2982    Accepted Submission(s): 2202
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
 

#include <stdio.h>
#include <math.h>
double y, ans; double f(double x){
return 6 * pow(x, 7) + 8 * pow(x, 6) +
7 * pow(x, 3) + 5 * x * x - y * x;
} double ff(double x){ //求导
return 42 * pow(x, 6) + 48 * pow(x, 5)
+ 21 * x * x + 10 * x - y;
} int main(){
int n;
scanf("%d", &n);
while(n--){
scanf("%lf", &y);
if(ff(0) >= 0) ans = f(0);
else if(ff(100) <= 0) ans = f(100);
else{
double left = 0, right = 100, mid;
while(left + 1e-8 < right){
mid = (left + right) / 2;
if(ff(mid) > 0) right = mid;
else if(ff(mid) < 0) left = mid;
else break;
}
ans = f(mid);
}
printf("%.4lf\n", ans);
}
return 0;
}

HDU2899 Strange fuction 【二分】的更多相关文章

  1. HDU 2899 Strange fuction [二分]

    1.题意:给一个函数F(X)的表达式,求其最值,自变量定义域为0到100 2.分析:写出题面函数的导函数的表达式,二分求导函数的零点,对应的就是极值点 3.代码: # include <iost ...

  2. hdu2899 Strange fuction

    在区间(0,100).在恒大二阶导数0.f(x)有极小值.用的最低要求的一阶导数值点: #include<math.h> #include<stdio.h> #include& ...

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

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

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

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

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

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

  6. Strange fuction hdu 2899

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

  7. hdu 2899 Strange fuction

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

  8. Strange fuction

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

  9. hdu 2899 Strange fuction (二分法)

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

随机推荐

  1. jenkinsfile or pipline 实现微服务自动发布回滚流程

    1 #!/usr/bin/env groovy Jenkinsfile node { //服务名称 def service_name = "**" //包名 def service ...

  2. 元素属性的添加删除(原生js)

    添加属性 odiv.setAttribute("title","hello div!"); odiv.setAttribute("class" ...

  3. JS——轮播图简单版

    1.小图标版本 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  4. Python 时间处理---------笔记

    时区处理&格式化 import pytz from datetime import datetime # 设置时区 timezone = pytz.timezone('Asia/Shangha ...

  5. [转]linux实时查看更新日志命令

    很多时候在调试生成或正式平台服务器的时候想查看实时的日志输出,在Linux中可以使用tail 或 watch来实现. 比如我们项目中有个 app.log 的日志文件,我们普通读取都使用 vi app. ...

  6. Linux下清空文件的常用方法

    1. 本人用的最多,感觉也是最方便的: > filename.log   2. : > filename.log 3. cat /dev/null > filename.log

  7. 几种fullpage用法及demo

    jQuery全屏滚动插件fullPage.js https://github.com/alvarotrigo/fullPage.js http://www.dowebok.com/77.html 全屏 ...

  8. HDU_1158_Employment Planning_dp

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. UICollectionView(一)基本概念

    整体预览 高等级的包含和管理(Top-level containment and management) UICollectionView UICollectionViewController UIC ...

  10. AcDbTable 类

    Table 例子学习笔记在这个例子中,ARX向我们展示了ACDBTABLE类的一些基本操作方法,ACDBTABLE类是ACAD2005及其以后的产品,应该是说ACDBDATATABLE的升级产品,Ac ...