NYOJ 题目969
来源:互联网 发布:java 获取spring bean 编辑:程序博客网 时间:2024/06/04 00:23
解方程(二)
时间限制:1000 ms | 内存限制:65535 KB
难度:3
- 描述
- Now, here is a fuction:
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.- 输入
- 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)
- 输出
- Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
- 样例输入
2100200
- 样例输出
-74.4291-178.8534
一开始看到题目也是比较没有头绪,后来经人提醒知道了方法,求出导数,因为其导数的正负可以决定方程的单调性而导数的最大最小值正负其实很大一部分是由Y决定的,所以先判断导数最大最小值,最大值小于零,说明最小值为F(100),最小值大于零,说明F(0)为最小值,有正有负需要寻找零点,零点的寻找利用二分查找法。
#include<stdio.h>#include<math.h>double fun1(double n,double y){ return 6*pow(n,7)+8*pow(n,6)+7*pow(n,3)+5*pow(n,2)-y*n;}double fun2(double n,double y){ return 42*pow(n,6)+48*pow(n,5)+21*pow(n,2)+10*n-y;}int main(){ double n,i,y; double fun1(double n,double y); double fun2(double n,double y); scanf("%lf",&n); while(n--) { scanf("%lf",&y); double number1=42*pow(100,6)+48*pow(100,5)+21*pow(100,2)+10*100; if(y>number1) { printf("%.4lf\n",fun1(100,y)); continue; } if(y<=0) { printf("%.4lf\n",fun1(0,y)); continue; } double a=0,b=100,c=fun2(0,y),d=fun2(100,y),e; while((b-a)>1e-10) { e=(a+b)/2; if(fabs(fun2(e,y))<1e-10) break; else if(fun2(e,y)*c<0) { d=fun2(e,y); b=e; } else { c=fun2(e,y); a=e; } } printf("%.4lf\n",fun1(e,y)); } return 0;}
阅读全文
0 0
- NYOJ 题目969
- NYOJ 题目10 skiing
- NYOJ 题目854 留恋
- NYOJ 题目94 cigarettes
- NYOJ 题目289 苹果
- nyoj 题目839 合并
- NYOJ 题目221 Tree
- nyoj题目34:韩信点兵
- nyoj题目813:对决
- nyoj题目822:画图
- nyoj题目463:九九乘法表
- NYOJ 题目915+-字符串
- nyoj题目611:练练
- NYOJ 题目1022
- NYOJ 题目1022合纵连横
- NYOJ---题目94cigarettes
- nyoj题目198:数数
- NYOJ---题目202红黑树
- 7.10-7.14校内集训总结反思
- JAVA中Stack和Heap的区别
- java logs 报错查看顺序
- Java类中的权限修饰符
- 面向对象的三大基本特征和五大基本原则
- NYOJ 题目969
- c++访问权限的控制
- SpringMVC学习(3):URL请求到Action的映射规则
- 详解java.util.Scanner
- java中比较两个日期Date的大小
- mySQL语句整理
- 查看JS对象中的所有属性
- Apache Commons 工具集使用简介
- Javascript获取网页各部分高度