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. 走进C++程序世界------继承和派生

    继承和派生 继承是面向对象编程语言的最重要方面之一,正确的使用继承可编写出设计良好,容易于维护和扩展的应用程序.下面是在其他博客中的总结: ****************************** ...

  2. MP3/WAV 播放

    一.编译libmad  1.先下载压缩包到本地,并解压  tar -xvzf  libmad-0.15.1b.tar.gz   -C   ./ 2.进入源代码文件夹并配置 编写一个配置文件,便于< ...

  3. java学习笔记day03

    1.二维数组,即一维护 int[][] arr1 = new int[3][2]; int[][] arr2 ={{2,4,3,6,22,7},{3,6,8,9},{10,13,24,5}}; pub ...

  4. UBUNTU系统root帐号解锁

    UBUNTU系统启动时默认以安装系统时输入的用户名进行登录.如:以非root帐号rusky登录系统,当我们做某些操作时系统提示需要输入root密码.但我们并没有设置过root密码.此时,可按如下操作为 ...

  5. NET基础课--NET中程序集0-1

    程序集 1.表现形式:.dll  和. exe . 2.程序集组成:PE头,CLR头,清单,元数据,CIL代码,资源文件.实际上这些内容包含在一个叫做Module的逻辑结构中. 单模块程序集:程序集就 ...

  6. webconfig 初认识

    本文摘自网络大神们,还有待补充. -------------------------------------------------------------------- .net 提供的是针对当前机 ...

  7. android——生成或者下载的图片在相册中找不到

    今天在写程序的时候,遇到了一个问题,就是生成的图片一直都不能在相册中显示出来,而且,就连通过发送Intent过去,都找不到.通过在网上搜索,发现了一个很好的方法. Intent intent = ne ...

  8. javascript模式——Decorator

    Decorator 模式是一种结构型模式,他意在促进代码的复用,是塑造子类的一个方式. 这种想法是基于,新增的属性,对于对象来说不是必须的基本功能.我们为特殊的对象添加自己的方法,而不是重新创建一个类 ...

  9. C++输入和输出

    本文转载:blog.csdn.net/zhanghaotian2011/article/details/8868577博客 输入和输出并不是C++语言中的正式组成成分。C和C++本身都没有为输入和输出 ...

  10. 【Lucene4.8教程之三】搜索

    1.关键类 Lucene的搜索过程中涉及的主要类有以下几个: (1)IndexSearcher:执行search()方法的类 (2)IndexReader:对索引文件进行读操作,并为IndexSear ...