记录编号 86172 评测结果 AAAAAAAAAA
题目名称 [UVa 1356] 桥上的绳索 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.079 s
提交时间 2014-01-21 21:06:47 内存使用 0.31 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<iomanip>
#include<queue>
#include<set>
#include<map>
using namespace std;
double Simpson(double (*f)(double),double eps,double a,double b,double A,double fa,double fb){//Simpson公式的一项
	//总的项值为A,左端函数值为fa,右端函数值为fb
	double mid=(a+b)/2,L,R;
	double fm=f(mid),fma=f((a+mid)/2),fmb=f((mid+b)/2);
	L=(fa+4*fma+fm)*(mid-a)/6;
	R=(fm+4*fmb+fb)*(b-mid)/6;
	if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15.0;
	return Simpson(f,eps/2,a,mid,L,fa,fm)+Simpson(f,eps/2,mid,b,R,fm,fb);
}
double Simpson(double (*f)(double),double eps,double a,double b){//用Simpson公式求f在[a,b]上的定积分
	double fa=f(a),fb=f(b);
	double sa=(fa+4*f((a+b)/2)+fb)*(b-a)/6;
	return Simpson(f,eps,a,b,sa,fa,fb);
}
double eps=1e-6;
double A,L1,D1,D,H,B,L;
double F(double x){
	return sqrt(1+4*A*A*x*x);
}
double arclen(double w,double h){
	A=4.0*h/(w*w);
	return Simpson(F,eps,0,w/2)*2;
}
double find(double a,double b){
	if(b-a<eps) return (a+b)/2;
	double mid=(a+b)/2;
	if(arclen(D1,mid)<L1) return find(mid,b);
	else return find(a,mid);
}
void work(int kase){
	scanf("%lf%lf%lf%lf",&D,&H,&B,&L);
	double n=ceil(B/D);
	D1=B/n;
	L1=L/n;
	//if(kase>1) printf("\n");
	printf("Case %d:\n%.2lf\n",kase,H-find(0,H));
}
int main(){
	freopen("bridge.in","r",stdin);
	freopen("bridge.out","w",stdout);
	int T;
	scanf("%d",&T);
	for(int i=1;i<=T;i++) work(i);
	return 0;
}