永远年轻,永远把简单的问题复杂化
一开始TLE了#2和#4,在while里加了个约束,交界点于100以内后就报WA了
下载了个数据看,发现系数可以为小数
OMG!!!
展示又臭又长的代码↓
#include<stdio.h>
#include<cmath>
void range(float a, float b, float c, float d) {
float left = -100, right = 100,
point1 = left, point2,point3;
if (a*pow(left, 3) + b * pow(left, 2) + c * left + d < 0) {
while (a*pow(point1, 3) + b * pow(point1, 2) + c * point1 + d < 0 && point1 <= 100) {
point1+=0.01;
}
//point1+=0.01;
point2 = point1;
while (a*pow(point2, 3) + b * pow(point2, 2) + c * point2 + d > 0 && point2 <= 100) {
point2+=0.01;
}
//point2+=0.01;
point3 = point2;
while (a*pow(point3, 3) + b * pow(point3, 2) + c * point3 + d < 0 && point3 <= 100) {
point3+=0.01;
}
//point3+=0.01;
}
else if (a*pow(left, 3) + b * pow(left, 2) + c * left + d > 0) {
while (a*pow(point1, 3) + b * pow(point1, 2) + c * point1 + d > 0 && point1 <= 100) {
point1+=0.01;
}
//point1+=0.01;
point2 = point1;
while (a*pow(point2, 3) + b * pow(point2, 2) + c * point2 + d < 0 && point2 <= 100) {
point2++;
}
//point2+=0.01;
point3 = point2;
while (a*pow(point3, 3) + b * pow(point3, 2) + c * point3 + d > 0 && point3 <= 100) {
point3++;
}
//point3+=0.01;
}
printf("%.2f %.2f %.2f", point1, point2, point3);
}
int main() {
float a, b, c, d;
scanf("%f %f %f %f", &a, &b, &c, &d);
range(a, b, c, d);
return 0;
}
看了洛谷的题解,发现有个盛金公式,百科太长了懒得看(ε=ε=ε=┏(゜ロ゜;)┛