题意:就是说一个用电控制球坠落的机器,两次坠落高度,以及发出时间到球坠地的时间分别是H1,T1,H2,T2,但是机器对信号响应有延迟,求延迟大小。
范围:绝对值<10,误差小于1e-4都可以AC
解法:这么小的绝对值,直接暴力.每次增加0.00001
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
#define inf 1073741823
#define llinf 4611686018427387903LL
#define PI acos(-1.0)
#define lth (th<<1)
#define rth (th<<1|1)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)
#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)
#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mkp(a,b) make_pair(a,b)
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
double h1,t1,h2,t2;
double calc(double x){
double tt1=t1-x;
double tt2=t2-x;
double g1=2.0*h1/(tt1*tt1);
double g2=2.0*h2/(tt2*tt2);
return fabs(g1-g2);
}
int main(){
scanf("%lf%lf%lf%lf",&h1,&t1,&h2,&t2);
double l=0.0;
double r=min(t1,t2);
double ans=0.0,t=llinf*1.0;
for(double x=l;x<=r;x+=0.000001){
double temp=calc(x);
if(temp<t){
t=temp;
ans=x;
}
}
printf("%.6f\n",ans);
return 0;
}