acm课程练习2--1002
题目描述
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代码
#include<iostream>#include<iomanip>#include<stdio.h>#include<cmath>using namespace std;double f_d(double res){return res*res*res*res *res*res*42 + res*res*res*res*res*48 + res*res*21 + res * 10;}double f(double res,double y){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;}int main(){//freopen("date.in", "r", stdin);//freopen("date.out", "w", stdout);int T;double a;double b,e,tem;cin>>T;for(int i=0;i<T;i++){cin>>a;if(f_d(100)<=a)cout<<fixed<<setprecision(4)<<f(100,a)<<endl;elseif(f_d(0)>=a)cout<<fixed<<setprecision(4)<<f(0,a)<<endl;else{b = 0, e = 100, tem = 50;while (fabs(f_d(tem) - a) >= 1e-7)if (f_d(tem)>a){e = tem;tem = (b + e) / 2;}else{b = tem;tem = (b + e) / 2;}cout<<fixed<<setprecision(4)<<f(tem,a)<<endl;}}}
acm课程练习2--1002的更多相关文章
- ACM课程学习总结
ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...
- ACM课程总结
当我还是一个被P哥哥忽悠来的无知少年时,以为编程只有C语言那么点东西,半个学期学完C语言的我以为天下无敌了,谁知自从有了杭电练习题之后,才发现自己简直就是渣渣--咳咳进入正题: STL篇: 成长为一名 ...
- 华东交通大学2016年ACM“双基”程序设计竞赛 1002
Problem Description 今天小学弟又训练完了,但是小学弟又不想看球赛,于是小学弟看马赛了.他发现马鞍是一个奇怪的东西.于是小学弟根据马鞍定义了一种马鞍数:在一个二位矩阵中,马鞍数在当前 ...
- 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 ...
- acm课程练习2--1005
题目描述 Mr. West bought a new car! So he is travelling around the city.One day he comes to a vertical c ...
- acm课程练习2--1003
题目描述 My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numb ...
- acm课程练习2--1001
题目描述 Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1002
Problem B Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2017年ACM“双基”程序设计竞赛 1002
Problem Description 一天YZW参加了学校组织交际舞活动,活动的开始活动方分别给男生和女生从1-n进行编号,按照从小到大顺时针的方式进行男女搭档分配,相同编号的男女组合成一对,例如一 ...
随机推荐
- Leetcode 074 Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- LeadTools答题卡识别方案
/// <summary> /// 批改操作 /// </summary> public AnswerCard DoCorrect(Stream AnserCardFile) ...
- setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientific Linux
This is a guide on setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientif ...
- Android jni编辑.so库
引自:http://www.cnblogs.com/sevenyuan/p/4202759.html 1. 在Eclipse中创建项目:TestJNI 2. 新创建一个class:TestJNI.ja ...
- 2.Add Two Numbers-两个单链表相加
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- xp添加右键"打开文件所在位置"
以下代码保存为czmb.vbs文件并放在C:\windwos目录下: Set OS = GetObject("winmgmts:\\.\root\cimv2")Set CF = O ...
- VBS调用keybd_event事件
----------------发送alt+v组合按键----------------------Set Wrap = CreateObject("DynamicWrapper") ...
- keybd_event 对应表
Option Explicit Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bSc ...
- 自定义VBS脚本(统计在指定文件中搜索字符串出现的次数)
'=========================================================================='' VBScript Source File - ...
- ob_get_contents()
ob_start();//buf1 echo 'multiple'; ob_start();//buf2 echo 'bufferswork'; $buf2 = ob_get_contents(); ...