我是真的服了一本通
  • 板块学术版
  • 楼主xxxas
  • 当前回复8
  • 已保存回复8
  • 发布时间2021/8/25 23:36
  • 上次更新2023/11/4 09:00:13
查看原帖
我是真的服了一本通
530581
xxxas楼主2021/8/25 23:36

两份代码运行结果一样,就给判错

AC的

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double eq(double x)
{
	return pow(x,5)-15*pow(x,4)+85*pow(x,3)-225*pow(x,2)+274*x-121>0;
}
int main()
{
	double l,r;
	l=1.5;r=2.4;
	while(fabs(r-l)>1e-7)
	{
		double mid=(l+r)/2;
		if(eq(mid)>0) l=mid;
		else r=mid;
	}
	printf("%.6f",l);
	return 0;
}

错的

#include<bits/stdc++.h>
using namespace std;
void sb(double s,double t)
{
	double md=(s+t)/2,hh;
	hh=pow(md,5)-15*pow(md,4)+85*pow(md,3)-225*pow(md,2)+274*md-121;
	if(hh==0)
	{
		printf("%.6f",md);
		return;
	}
	if(hh<0 && s<t)
	{
		sb(s,md);
	}
	if(hh>0 && s<t)
	{
		sb(md,t);
	}
	return;
}
int main()
{
	sb(1.5,2.4);
	return 0;
}

调了我一小时。。。

2021/8/25 23:36
加载中...