Problem A: Advanced Mathematics
来源:互联网 发布:原始传奇转生数据 编辑:程序博客网 时间:2024/05/10 01:57
Problem A: Advanced Mathematics
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 28 Solved: 17
[Submit][Status][Web Board]
Description
Alice, your goddess, is going out with Bob, her boyfriend, but her advanced mathematics homework stops her. She is very sad and turns to you for help.
Her homework are quite simple. A function is given and you are asked to calculate its monotone intervals.
Input
Input file contains several test cases.
In each test case, there is one line containing four positive integers a, b, c and d (1<=a, b, c, d<=1000) indicating the coefficients of the function.
Input file ends with an EOF.
Output
For each test case, print the monotone intervals of f(x) separated by a space. Output “(l, r)+” (without quotes) if interval (l, r) are monotone increasing, and “(l, r)-” for monotone decreasing intervals. All intervals should be sorted by left end increasing. “-inf” (without quotes) indicates negative infinity and “+inf” (without quotes) for positive infinity. All numbers should be rounded to 4 digits after decimal point. For more detailed output form, refer to the sample output.
Sample Input
1 4 3 11 3 3 2
Sample Output
(-inf, -2.2153)+ (-2.2153, -0.4514)- (-0.4514, +inf)+(-inf, +inf)+
HINT
题意:求一个一元三次方程的单调区间和单调递增还是递减。
好吧。将其求导就知道极值点了,然后再判断左右的大小就知道是递增还是递减了,一个麻烦的数学水题。
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>using namespace std;int a,b,c,d;int main(){while (~scanf("%d%d%d%d",&a,&b,&c,&d)){a=3*a;b=2*b;int x=b*b-4*a*c;if (x<0){double s=a+b+c;if (s<0)printf("(-inf, +inf)-\n");elseprintf("(-inf, +inf)+\n");continue;}else{double s1=(0-b+sqrt(x))/(2.0*a);double s2=(0-b-sqrt(x))/(2.0*a);if (s1>s2){double t=s1;s1=s2;s2=t;}if (x==0){a/=3;b/=2;double k1=a*pow((s1-1.1),3)+b*pow((s1-1.1),2)+c*(s1-1.1);double k2=a*pow(s1,3)+b*pow(s1,2)+c*s1;double k3=a*pow((s1+1.1),3)+b*pow((s1+1.1),2)+c*(s1+1.1);if ((k2-k1)*(k3-k2)>=0){if (k3-k2>0)printf("(-inf, +inf)+");elseprintf("(-inf, +inf)-");}else{if (k2-k1>0)printf("(-inf, %.4lf)+ ",s1);elseprintf("(-inf, %.4lf)- ",s1);if (k3-k2>0)printf("(%.4lf, +inf)+",s1);else printf("(%.4lf, +inf)-",s1);}cout<<endl;}else{a/=3;b/=2;double k1=a*pow((s1-1),3)+b*pow((s1-1),2)+c*(s1-1);double k2=a*pow(s1,3)+b*pow(s1,2)+c*s1;double k3=a*pow(s2,3)+b*pow(s2,2)+c*s2;double k4=a*pow((s2+1),3)+b*pow((s2+1),2)+c*(s2+1);if (k2-k1>0)printf("(-inf, %.4lf)+ ",s1);elseprintf("(-inf, %.4lf)- ",s1);if (k3-k2>0)printf("(%.4lf, %.4lf)+ ",s1,s2);elseprintf("(%.4lf, %.4lf)- ",s1,s2);if (k4-k3>0)printf("(%.4lf, +inf)+\n",s2);else printf("(%.4lf, +inf)-\n",s2);}}} return 0;}
0 0
- Problem A: Advanced Mathematics
- How to Solve a Mathematics Problem?
- poj 2158 A Difficult Mathematics Problem
- LaTeX/Advanced Mathematics
- Mathematics
- Mathematics
- Mathematics
- 视频推荐:Dimensions - A walk through mathematics
- jsMath: A Method of Including Mathematics in Web Pages
- Concrete Mathematics(2nd Edition) - A Note on Notation
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- startActivity跳转出错
- 使用JNDI连接数据库
- [Phonegap+Sencha Touch] 移动开发1、准备工作
- Nyoj 570 欧拉函数求和
- IntelliSense: #error 指令: Please use the /MD switch for _AFXDLL builds
- Problem A: Advanced Mathematics
- Unity3D教程:iTween插件的介绍和用法
- pdo类,分页类
- Linux deadline io 调度算法
- oracle中的约束
- 我读经典(4):读《打造Facebook》有感
- 今天发现一个不错的博客,地址是~~~
- POJ 1519 Digital Roots
- 替换Android系统镜像system.img的方法