Problem A: Advanced Mathematics

Problem A: Advanced Mathematics

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 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 1
1 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");
			else
				printf("(-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)+");
					else
						printf("(-inf, +inf)-");
				}
				else
				{
					if (k2-k1>0)
						printf("(-inf, %.4lf)+ ",s1);
					else
						printf("(-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);
				else
					printf("(-inf, %.4lf)- ",s1);
				if (k3-k2>0)
					printf("(%.4lf, %.4lf)+ ",s1,s2);
				else
					printf("(%.4lf, %.4lf)- ",s1,s2);
				if (k4-k3>0)
					printf("(%.4lf, +inf)+\n",s2);
				else 
					printf("(%.4lf, +inf)-\n",s2);	
			}
		}
	} 
	return 0;
}



【源码免费下载链接】:https://renmaiwang.cn/s/os2te 大整数乘法是计算机科学中的一个重要领域,特别是在算法设计和数学计算中有着广泛应用。它涉及到处理超过标准整型变量范围的数值运算。在C++编程语言中,处理大整数通常需要自定义数据结构和算法,因为内置的`int`、`long long`等类型无法满足大整数的存储和计算需求。以下是对这个主题的详细阐述:1. **大整数数据结构**: 在C++中,实现大整数通常采用数组或链表来存储每一位数字。例如,可以使用一个动态分配的数组,每个元素表示一个位上的数字,从低位到高位排列。这种数据结构允许我们方便地进行加减乘除等操作。2. **乘法算法**: - **暴力乘法**:最直观的方法是类似于小学的竖式乘法,但效率较低,时间复杂度为O(n^2)。 - **Karatsuba算法**:由Alexander Karatsuba提出,将两个n位数的乘法转化为三个较小的乘法,时间复杂度为O(n^1.585)。 - **Toom-Cook算法**:比Karatsuba更通用,通过多项式插值和分解进行计算,有不同的变体,如Toom-3、Toom-4等。 - **快速傅里叶变换(FFT)**:当处理的大整数可以看作是多项式系数时,可以利用FFT进行高效的乘法,时间复杂度为O(n log n)。FFT在数论和密码学中尤其重要。3. **算法实现**: 实现这些算法时,需要考虑如何处理进位、溢出等问题,以及如何优化代码以提高效率。例如,使用位操作可以加速某些步骤,同时要确保代码的正确性和可读性。4. **源代码分析**: "大整数乘法全解"的源代码应包含了上述算法的实现,可能还包括了测试用例和性能比较。通过阅读源码,我们可以学习如何将理论算法转化为实际的程序,并理解各种优化技巧。5. **加说明**: 通常,源代码附带的说明会解释
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值