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. SQL递归查询实现跟帖盖楼效果

    网易新闻的盖楼乐趣多,某一天也想实现诸如网易新闻跟帖盖楼的功能,无奈技术不佳(基础不牢),网上搜索了资料才发现SQL查询方法有一种叫递归查询,整理如下: 一.查询出 id = 1 的所有子结点 wit ...

  2. android之ListPreference的用法_PreferenceActivity用法

    首先,我们明确,preference是和数据存储相关的.        其次,它能帮助我们方便的进行数据存储!为什么这个地方一定要强调下方便的这个词呢?原因是,我们可以根本就不使用,我们有另外的N种办 ...

  3. react redux 相关技术

    React全都是围绕着组件的, 所以React基础也就是:写组件的jsx.组件的生命周期以及组件的属性和状态.jsx,只要是用过html模板的分分钟就能写了: 所谓生命周期就是组件在创建.销毁.更新阶 ...

  4. 安装Oracle11后在SQL Developer启动时提示:enter the full pathname for the java.exe

    1) Open the file ..\sqldeveloper\sqldeveloper\bin\sqldeveloper.conf and add the following line to se ...

  5. python 笔记4-- 函数式编程

    高阶函数 把函数作为参数传入,这样的函数称为高阶函数,函数式编程就是指这种高度抽象的编程范式. 在python中 函数也是一种变量 def add(x, y, f): return f(x) + f( ...

  6. 笔记本开通手机WiFI热点

    启用虚拟wifi: netsh wlan set hostednetwork mode=allow ssid=liuyuduen key=liuyuduen 关闭虚拟Wifi: netsh wlan ...

  7. JS--Div中数据滚动到最后一条重新从头开始滚动

    在做东西时要求让数据滚动,且滚动到最后一条时,从头再开始滚动,样图如下:

  8. dojo.hasClass/dojo.addClass/dojo.removeClass/dojo.toggleClass/dojo.repalceClass

    dojo.hasClass(/*DomNode*/node or DomIdstring,/*String*/classString)//如果节点中有特定的类,那么返回ture,否则返回false d ...

  9. struts1:Struts配置文件初解

    struts-config.xml是Struts的核心文件.该文件可配置各种组件,包括,FormBeans,Actions,ActionMappings,全局转发GlobalForwards,数据源D ...

  10. 反片语(map)

    输入一些单词,找出所有满足如下条件的单词: 该单词不能通过字母重排,得到输入文本中的另外一个单词. 在判断是否满足条件时,不区分大小写,但输出保留输入中的大小写,按字典序进行排列(所有大写字母在小写字 ...