Strange fuction

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

Total Submission(s): 3809    Accepted Submission(s): 2760

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
 
Author
Redow
 
很水的题 但是WA了几次

虽说最后要求1e-4的精度 

但是因为求最小值 所以注意所求的x值精度 至少要1e-6 所以请注意





#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
double y;
void init()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
}
double cal1(double x)
{
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}
double cal2(double x)
{
return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;
}
void solve()
{
double L=0,R=100,ans=1e10;
double temp1=cal1(L),temp2=cal1(R);
if(temp1<ans) ans=temp1;
if(temp2<ans) ans=temp2;
double ANS;
while(R-L>1e-6)
{
double m=(R+L)/2;
if(cal2(m)>0) R=m;
else if(cal2(m)<0) L=m;
else { ANS=m;break; }
}
ANS=R;
if(cal1(ANS)<ans) ans=cal1(ANS);
printf("%.4lf\n",ans); }
int main()
{
// init();
int T;
cin>>T;
while(T--)
{
cin>>y;
solve();
}
return 0;
}

【精度问题】【HDU2899】Strange fuction的更多相关文章

  1. HDU2899 Strange fuction 【二分】

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

  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. hdu 2899 Strange fuction

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

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

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

  6. Strange fuction

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

  7. hdu 2899 Strange fuction (二分法)

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

  8. Strange fuction hdu 2899

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

  9. Strange fuction

    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 <=1 ...

随机推荐

  1. myeclipse修改tomcat端口

    myeclipse自带的tomcat可以直接在myeclipse下面进行配置,但是如果是配置的tomcat 只能自己手动修改了

  2. Android学习总结——适配器

    适配器是AdapterView视图(如ListView - 列表视图控件.Gallery - 缩略图浏览器控件.GridView - 网格控件.Spinner - 下拉列表控件.AutoComplet ...

  3. CSS-边框-效果

    1.1边框 其中边框圆角.边框阴影属性,应用十分广泛,兼容性也相对较好,具有符合渐进增强原则的特性,我们需要重点掌握. 1.1.1边框圆角 border-radius 每个角可以设置两个值,x值,y值 ...

  4. 关于ASP.NET 中站点地图sitemap 的使用

    在ASP.NET  MVC 如此火热的时期,我竟然不适时宜的谈起ASP.NET ,恐怕会引来一阵嘲笑.最为无趣的是,讲解的竟然还是其中的一个控件.oh~~  my god!my out! ^_^ Si ...

  5. EF Code Frist

    EF:学习资料 http://www.cnblogs.com/libingql/category/366833.html

  6. CAA调试

    在需要调试的Module(*.m)上右键,选择属性,命令位置选择你的framework目录    路径选择对应工程目录下的\intel_a(或者Win64    --    64位机器) 然后就可以尽 ...

  7. iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案

    问题描述 iOS系统下,移动web页面,inpu获取焦点弹出系统虚拟键盘时,偶尔会出现挡住input的情况,尽管概率不大,但是十分影响用户体验. 问题重现 原始页面:页面中有header.main.f ...

  8. Leetcode算法刷题:第14题 Longest Common Prefix

    Longest Common Prefix 题目 给予一个列表,元素为字符串,写一个程序找出最长公共前缀 解题思路 先比较两个字符串,如果第一个字符不一样,则返回空值,比较完成后,用这个公共字符串和下 ...

  9. python socket 编程之一:编写socket的基本步骤

    一.socket 编写server的步骤: 1.第一步是创建socket对象.调用socket构造函数.如: socket = socket.socket( family, type ) family ...

  10. Max Sum(hd P1003)

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...