Loading
NOIP2004提高組 合併果子
NOIP2000提高組 進制轉換

NOIP2001提高組 一元三次方程求解

Freddy posted @ 2011年10月08日 03:41 in NOIP with tags NOIP c++ 枚舉 模擬 , 3375 阅读

问题描述
有形如:ax3+bx2+cx+d=0  这样的一个一元三次方程。给出该方程中各项的系数(a,b,c,d  均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差的绝对值>=1。要求由小到大依次在同一行输出这三个实根(根与根之间留有空格),并精确到小数点后2位。
提示:记方程f(x)=0,若存在2个数x1和x2,且x1<x2,f(x1)*f(x2)<0,则在(x1,x2)之间一定有一个 根。

样例
输入:1   -5   -4   20
输出:-2.00   2.00   5.00

【分析】

由於精度不大,直接枚舉即可。

一下代碼參考了BYVoid(http://www.byvoid.com)的代碼~他的代碼比我的簡練多了~

#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	double a,b,c,d,x,v;
	int X;
	freopen("3cfc.in","r",stdin);
	freopen("3cfc.out","w",stdout);
	cin>>a>>b>>c>>d;
	for (X=-10000;X<=10000;x=(++X)/100.0)
	{
		v=a*x*x*x+b*x*x+c*x+d;
		if (v>=-0.01 && v<=0.01)	
			printf("%.2lf ",x);	
	}
	return 0;
}

正在连接评测机...

 

已连接到评测机

GRID 1
名称 Flitty
系统版本 1.00
备注 COGS 1号评测机 Flitty

正在编译...

编译成功

 

测试点 结果 得分 运行时间 内存使用 退出代码
1 正确 20 0.027 s 273 KB 0
2 正确 20 0.001 s 273 KB 0
3 正确 20 0.001 s 273 KB 0
4 正确 20 0.001 s 273 KB 0
5 正确 20 0.001 s 273 KB 0

运行完成

运行时间 0.031 s

平均内存使用 273 KB

测试点通过状况 AAAAA

得分:100

恭喜你通过了全部测试点!

 

Write My Essay 说:
2019年4月30日 07:14

When x=0, y=−3<0, and when x=1, y=1>zero, so since the curve is continuous (we can draw it without taking our pen off the paper), it has gothas reduce the x-axis someplace betwwen x=0 and x=1. Could it cut the optimistic x-axis greater than once? Good, we will see that x3 and 3x2 are increasing services for optimistic x.
If there have been to be a second constructive root, the curve would must shrink someplace for x>0, which is not feasible. So the curve has a single optimistic root.

Alyssa 说:
2022年12月13日 22:40

There has been a lot of research on how to solve unary cubic equations efficiently, and the NOIP2001 Improvement Group has made some significant progress in this real estate expert Smithfield area. They have developed an algorithm that can solve these equations much faster than previous methods, and it is also more accurate. This is a big step forward in the field of mathematics, and it will help to solve many problems that have been difficult to solve in the past.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter