【精度问题】【HDU2899】Strange fuction
Strange fuction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3809 Accepted Submission(s): 2760
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.
2
100
200
-74.4291
-178.8534
#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的更多相关文章
- HDU2899 Strange fuction 【二分】
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu2899 Strange fuction
在区间(0,100).在恒大二阶导数0.f(x)有极小值.用的最低要求的一阶导数值点: #include<math.h> #include<stdio.h> #include& ...
- ACM : HDU 2899 Strange fuction 解题报告 -二分、三分
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 2899 Strange fuction
http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...
- hdoj 2899 Strange fuction【二分求解方程】
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Strange fuction
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 2899 Strange fuction (二分法)
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Strange fuction hdu 2899
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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 ...
随机推荐
- html 表格中文字的背景色
- Ajax——ajax调用数据总结
在做人事系统加入批量改动的功能中,须要将前台中的数据传给后台.后台并运行一系列的操作. 通过查询和学习了解到能够通过ajax将值传入到后台,并在后台对数据进行操作. 说的简单点.就是ajax调用后台的 ...
- Android studio教程:[4]真机测试
有了Android studio这么好用的软件,自然要有一部不错的安卓手机,然后在真机上测试自己的程序,那样才能更好的发现程序中存在的问题,毕竟模拟器不是真正的手机嘛. 工具/原料 Android s ...
- 导出Eclipse环境配置
第一种方法: Eclipse的 File -> Export(导出), 在窗口中展开 General(常规) -> Perferences(首选项)-->Export all(全部导 ...
- Stack的三种含义(转载--阮一峰)
作者: 阮一峰 学习编程的时候,经常会看到stack这个词,它的中文名字叫做"栈". 理解这个概念,对于理解程序的运行至关重要.容易混淆的是,这个词其实有三种含义,适用于不同的场合 ...
- Mysql优化之创建高性能索引(一)
1.索引基础 索引对于良好的性能非常关键.尤其是当表中的数据量越来越大时,索引对性能的影响愈发重要.但是不恰当的索引随着数据量的增加,也会使整个数据库的性能下降. 举个例子: ; 如果在id上建立索引 ...
- js中邦定事件与解绑支持匿名函数
和一个朋友讨论了一下,DOM2绑定方式都是有名的函数,匿名的处理起来有些麻烦,而且即使是有名的函数,在IE低版本的浏览器也是解除不掉的,this指向需要修改,着实费了一番功夫,这个是兼容ie低版本的, ...
- html5 canvas 一个漫天飞雪的效果
很棒的下雪效果 代码奉上 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...
- Thinkphp excel导入导出
挺有用处的存一下 1.去PHPexcel 官网下载最新的程序下来 ☞ 飞机在这里 我用的是1.78 放在vender 里面 在 function.php 写两个方法 路径当然是这个 ☞Commo ...
- 国内好用的公用DNS 服务器。
阿里 AliDNS 223.5.5.5 223.6.6.6 CNNIC SDNS 1.2.4.8 210.2.4.8 Google DNS 8.8.8.8 8.8.4.4 OpenDNS 208.67 ...