题目描述

Now, here is a fuction:
  F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (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

大意

求函数在区间[0,100]的最小值

思路

对函数求导得F’(x)=42* x^6+48x^5+21x^2+10x-y

,再对导函数求导,发现导函数是单调递增的。

得到结论,函数的最小值点为

42
x^6+48x^5+21x^2+10*x=y的根。

程序应首先判断根是否在[0,100]区间内,分为三种情况讨论。

这一题的代码与第一题差别不大,是第一题的变形

AC代码

  1. #include<iostream>
  2. #include<iomanip>
  3. #include<stdio.h>
  4. #include<cmath>
  5. using namespace std;
  6. double f_d(double res)
  7. {
  8. return res*res*res*res *res*res*42 + res*res*res*res*res*48 + res*res*21 + res * 10;
  9. }
  10. double f(double res,double y){
  11. return res*res*res*res*res*res*res*6 + res*res*res*res*res*res*8 + res*res*res*7 + res*res* 5-res*y;
  12. }
  13. int main(){
  14. //freopen("date.in", "r", stdin);
  15. //freopen("date.out", "w", stdout);
  16. int T;
  17. double a;
  18. double b,e,tem;
  19. cin>>T;
  20. for(int i=0;i<T;i++){
  21. cin>>a;
  22. if(f_d(100)<=a)
  23. cout<<fixed<<setprecision(4)<<f(100,a)<<endl;
  24. else
  25. if(f_d(0)>=a)
  26. cout<<fixed<<setprecision(4)<<f(0,a)<<endl;
  27. else{
  28. b = 0, e = 100, tem = 50;
  29. while (fabs(f_d(tem) - a) >= 1e-7)
  30. if (f_d(tem)>a){
  31. e = tem;
  32. tem = (b + e) / 2;
  33. }
  34. else{
  35. b = tem;
  36. tem = (b + e) / 2;
  37. }
  38. cout<<fixed<<setprecision(4)<<f(tem,a)<<endl;
  39. }
  40. }
  41. }

acm课程练习2--1002的更多相关文章

  1. ACM课程学习总结

    ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...

  2. ACM课程总结

    当我还是一个被P哥哥忽悠来的无知少年时,以为编程只有C语言那么点东西,半个学期学完C语言的我以为天下无敌了,谁知自从有了杭电练习题之后,才发现自己简直就是渣渣--咳咳进入正题: STL篇: 成长为一名 ...

  3. 华东交通大学2016年ACM“双基”程序设计竞赛 1002

    Problem Description 今天小学弟又训练完了,但是小学弟又不想看球赛,于是小学弟看马赛了.他发现马鞍是一个奇怪的东西.于是小学弟根据马鞍定义了一种马鞍数:在一个二位矩阵中,马鞍数在当前 ...

  4. acm课程练习2--1013(同1014)

    题目描述 There is a strange lift.The lift can stop can at every floor as you want, and there is a number ...

  5. acm课程练习2--1005

    题目描述 Mr. West bought a new car! So he is travelling around the city.One day he comes to a vertical c ...

  6. acm课程练习2--1003

    题目描述 My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numb ...

  7. acm课程练习2--1001

    题目描述 Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and ...

  8. 华东交通大学2015年ACM“双基”程序设计竞赛1002

    Problem B Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  9. 华东交通大学2017年ACM“双基”程序设计竞赛 1002

    Problem Description 一天YZW参加了学校组织交际舞活动,活动的开始活动方分别给男生和女生从1-n进行编号,按照从小到大顺时针的方式进行男女搭档分配,相同编号的男女组合成一对,例如一 ...

随机推荐

  1. TortoiseGit - Win7使用Gitblit搭建Git服务器教程

    第一步:下载Java并且安装 第二步:配置Java环境变量环境变量 --> 系统变量1新建:变量名:JAVA_HOME变量值:D:\Program Files (x86)\Java\jdk1.6 ...

  2. java基础(1)

    class test { static { a=3; //System.out.println(a); } static int a = 1; String b = "ff"; p ...

  3. use 2 stacks to simulate a queue

    class Stack{ private: ; ]; public: void push(int n); int pop(); int peek(); int size(); }; void Stac ...

  4. Flask -- 内容管理系统

    例子: # content_manager.py # 把TOPIC存在一个字典里,key为关键字,value为二维数组# TOPIC_DICT['Django'][0]为Title,TOPIC_DIC ...

  5. 类型“GridView”的控件必须放在具有 runat=server 的窗体标记内?

    Response.AddHeader("content-disposition", "attachment;filename=CRM.xls") Respons ...

  6. UTF8,UTF16,UTF32,UTF16-LE,UTF16-BE,GBK 之间的转换

    Unicode是Unicode.org制定的编码标准,目前得到了绝大部分操作系统和编程语言的支持.Unicode.org官方对Unicode的定义是:Unicode provides a unique ...

  7. Centos7下安装pip

    Linux 通过 pip 安装使用 Shadowsocks - CentOS 7 (06) Pip是安装Python包的工具,提供了安装.列举已安装包.升级以及卸载包的功能.Pip 是对easy_in ...

  8. servlet第1讲初识

  9. .net文件上传,客户端用jquery file upload

    <%@ WebHandler Language="C#" Class="Handler" %> using System; using System ...

  10. 关于C++中虚函数表存放位置的思考

    其实这是我前一段时间思考过的一个问题,是在看<深入探索C++对象模型>这本书的时候我产生的一个疑问,最近在网上又看到类似的帖子,贴出来看看: 我看到了很多有意思的答案,都回答的比较好,下面 ...