题目描述

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. WTL 设置 SDI 主窗口初始大小的方法

    在窗口创建之前添加一段代码 一般窗口创建函数为 wndMain.CreateEx(); 在此函数前添加 1: RECT rect = {x, y, width, height}; 然后将创建窗口函数改 ...

  2. tomcat源码分析(二)启动过程

    在Catalina的load方法中,首先初始化Server组件. // Start the new server if (server instanceof Lifecycle) { try { se ...

  3. great C++ socket library

    NETLINK: http://netlinksockets.sourceforge.net/index.html

  4. use 2 stacks to simulate a queue

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

  5. Fiddler AutoResponder正则替换

    今天感冒,写简单些. Fiddler AutoResponder正则替换: regex:(?inx).+20150826_1_1_386.mp4/playlist.m3u8.*$ .表示任意字符 *: ...

  6. FZU 1502 Letter Deletion

    最长公共子序列. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...

  7. Windows进程间通信(下)

    六.动态数据交换(Dynamic Data Exchange) 动态数据交换(DDE)是使用共享内存在应用程序之间进行数据交换的一种进程间通信形式.应用程序可以使用DDE进行一次性数据传输,也可以当出 ...

  8. VBS一键配置VOIP脚本(其中包括VBS操作JS网页中的按钮事件--直接执行确认按钮中的脚本代码)

    Dim ws,fso,IESet IE = WScript.createobject("InternetExplorer.Application")Set ws = WScript ...

  9. MFC中为菜单或按钮添加快捷键功能

    1.新建一快捷键资源,ACCELERATOR,关联相应的ID号,下图所示中,其中,第一个ID为自定义快捷键ID,按CTRL+R,此时响应该ID以应的消息响应函数, 第二个ID为菜单ID,此时按CTRL ...

  10. JavaScript高级程序设计:第二十章

    第二十章 一.语法 JSON的语法可以表示以下三种类型的值: (1)简单值 (2)对象 JSON的对象与javascript字面量有一些不同.例如,在javascript中,前面的对象字面量可以写成下 ...