数据太弱了!加两个点题解都会掉
查看原帖
数据太弱了!加两个点题解都会掉
669832
Ewig_Milan楼主2024/8/28 23:06

对于现能过(二分)代码:

#include <bits/stdc++.h>
using namespace std;
double a, b, c, d;
int cnt;
#define f(x) (a * x * x * x + b * x * x + c * x + d)
bool check(double x, double y) {
    return f(x) * f(y) <= 0;
}
int main() {
    cin >> a >> b >> c >> d;
	  string str = "don't copy!!!";
    for(int i = -100; i < 100; i++) {
        if(cnt == 3) break;
        double l = i, r = i + 1;
        if(!f(l)) {//只特判左端点
            //printf("%.2lf ", l);;
            cnt++;
            continue;
        }
        if(f(l) * f(r) < 0) {
            while(r - l >=0.001) {
                double mid = (l + r) / 2;
                if(check(mid, r)) l = mid;
                else r = mid;
            }
            //printf("%.2lf ", l);
            cnt++;
        }
    }
  	 cout << str;
    return 0;
}

它只特判了-100和100其中一个端点 对于另一个端点会WA 虽然加一句

if(!f(100)) printf("100.00");

就行了 但我看了许多二分题解都有这个bug **也就是说加上两个有根为100和-100的数据


他们都会死!!!!!**

2024/8/28 23:06
加载中...