求助!枚举为什么不对

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>

using namespace std;

double a,b,c,d;

void search(double x1,double x2)
{
double ans;
double y1 = a*x1*x1*x1 + b*x1*x1 + c*x1 + d;
double y2 = a*x2*x2*x2 + b*x2*x2 + c*x2 + d;
if(y1 * y2 < 0 && x1!=x2)
{
x1 += 0.01;
}
x1 -= 0.01;
ans = x1;
cout << ans << " ";
}

int main()
{
/* freopen("1116.in","r",stdin);
freopen("1116.out","w",stdout);*/

double x1 = -100.00,x2 = -99.00; //x1为head,x2为tail ,x2>x1,f(x2)*f(x1)<0
int y1 = 0 ,y2 = 0;
int amount = 0,i = 0; //ans个数
cin >> a >> b >> c >> d;
y1 = a*x1*x1*x1 + b*x1*x1 + c*x1 + d;
y2 = a*x2*x2*x2 + b*x2*x2 + c*x2 + d;
while(amount < 3)
{
if(y1 * y2 < 0)
{
x1 = x2 - 1;
search(x1,x2);
amount ++;
x2++;
x1++;
}
else
{
x2++;
y2 = a*x2*x2*x2 + b*x2*x2 + c*x2 + d;
}
}

/* fclose(stdin);
fclose(stdout);*/
return 0;
}
枚举错在哪啊

0 条评论

目前还没有评论...

信息

ID
1116
难度
5
分类
搜索 | 枚举 点击显示
标签
递交数
7786
已通过
2832
通过率
36%
被复制
14
上传者