AC,但是有疑问&&敲烂警钟
查看原帖
AC,但是有疑问&&敲烂警钟
655485
eifiwohie楼主2024/9/15 11:00
#include <bits/stdc++.h>
using namespace std;
double a,b,c,d;
double getnum(double g){
	double ans=double(a)*(g*g*g)+(double(b)*(g*g))+(double(c)*g)+double(d);
	return ans;
}
int main(){
	cin>>a>>b>>c>>d;
	for(double i=-10000;i<=10000;i++){
		double g=double(i)/double(100);
		double t=0;
		if(getnum(g)*getnum(g+0.01)<0&&getnum(g)*getnum(g+0.01)!=-0){

			if(abs(getnum(g))>abs(getnum(g+0.01))){
				t=g+0.01;
				printf("%.2lf ",t);
			}else{
				t=g;
				printf("%.2lf ",t);
			}
		}

		if(getnum(g)*getnum(g-0.01)==0){
			if(!getnum(g)){
				t=g;
				printf("%.2lf ",t);
			}
		}
	}
	return 0;
}

程序运行时有几个数据带入会计算出-0这个违背常理的结果,只得特判,请问各位大佬这是为什么?

2024/9/15 11:00
加载中...