题目描述

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. PHP7新功能及语法变化总结

    1.标量类型声明有两种模式: 强制 (默认) 和 严格模式. 现在可以使用下列类型参数(无论用强制模式还是严格模式): 字符串(string), 整数 (int), 浮点数 (float), 以及布尔 ...

  2. php 积少成多!

  3. HttpReceiveRequestEntityBody 使用应注意的地方

    如果EntityBody数据很大,调用此函数是不能完全接收全部数据的,我们不能简单的判断 1: BYTE* pBuffer = new BYTE[4096]; 2: ZeroMemory(pBuffe ...

  4. chapter 12_2 保存无环的table

    保存table有几种方法,选用哪种方法取决于对table的结构作出了哪些限制性的假设 第一个方法: function serialize(o) if type(o) == "number&q ...

  5. java反射机制(2)

    首先,我们在开始前提出一个问题: 1.在运行时,对于一个java类,能否知道属性和方法:能否去调用它的任意方法? 答案是肯定的. 本节所有目录如下: 什么是JAVA的反射机制 JDK中提供的Refle ...

  6. 值得一提:关于 HDFS 的 file size 和 block size

    转 http://blog.csdn.net/samhacker/article/details/23089157?utm_source=tuicool&utm_medium=referral ...

  7. Understanding Neural Networks Through Deep Visualization

    当数据一层一层通过更多的卷积层时,你可以得到的特征图像代表的特征就会更加的复杂. 在网络的最后,你也许可以得到一个抽象的物体.如果你想通过可视化方法在卷积神经网络中看到更多的信息.这里有一个工具方便你 ...

  8. Redis简介三

    目录 一.Key 二.String 三.Hash 四.List 五.Set 六.SortedSet 七.Pub/Sub 八.Transaction 九.Script 十.Connection 十一.S ...

  9. sping时间触发器

    而在Spring里很好的集成了Quartz,在xml文件里面配一下时间就可以自动执行,不需要写一行代码. <bean id="methodInvokingJobDetail" ...

  10. androidstudio--gsonformat--超爽的数据解析方式

    很久以前写json解析用原始的解析json的方法,后来为了加快开发进度,开始使用gson,fastjson等第三方jar包来进行json解析,为了保持apk足够小,不因为引入jar包导致apk文件过大 ...