题意:一个球想从0弹到d,中间有n个木板在Pos i,高度为Height i ,问在至多落下Bn次的情况下(不包括首尾),最小初始速度是多少。
示意圖:
范围:Bn<=15,n<=10,d<=10000,输入都为整数
解法:
首先可以发现,当落地次数一定时,落点是可以确定的,且如果弹不过去,必然是初始速度的Vy过小(上下为Y轴,左右X轴),那么二分Vy,通过计算得到Vx,然后判断是否能否跳过所有木板,就可二分得到一个合法的Vy区间,但是这时候初始速度不一定是最小的,然后再三分一下Vy找到一个最小的初始速度即可。
#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; #define NN 10010 int len,n,m; struct node{ int pos,h; }a[NN]; double dis[NN]; double eps=1e-7; int pd(int num,double vy){ double dt=2.0*vy; double t=double(num)*dt; double vx=double(len)/t; rep(i,1,num){ double l=dis[i-1]; double r=dis[i]; rep(j,1,n){ if(double(a[j].pos)<l||double(a[j].pos)>r)continue; double ct=double(a[j].pos)*t/double(len); ct-=floor(ct/dt+eps)*dt; if(vy*ct-0.5*ct*ct<double(a[j].h))return 0; } } return 1; } double gettime(int i,double vy){ double dt=2.0*vy; double t=double(i)*dt; double vx=double(len)/t; return(sqrt(vx*vx+vy*vy)); } int main(){ scanff(len); scanff(n); scanff(m); rep(i,1,n){ scanff(a[i].pos); scanff(a[i].h); } double ans=llinf*1.0; dis[0]=0; rep(i,1,m+1){ int ok=0; if(len%i==0){ int d=len/i; rep(k,1,n){ if(a[k].pos%d==0){ ok=1; break; } } } if(ok)continue; rep(j,1,i){ double dx=double(len)/double(i); dis[j]=dx*double(j); } double l=0.0,r=inf*1.0; rep(j,1,300){ double mid=(l+r)/2.0; if(pd(i,mid))r=mid; else l=mid; } l=l;r=inf*1.0; rep(j,1,300){ double d1=(l+r)/2.0; double d2=(d1+r)/2.0; if(gettime(i,d1)<gettime(i,d2))r=d2; else l=d1; } ans=min(ans,gettime(i,l)); } printf("%.8f\n",ans); return 0; } /* 10 1 0 5 2 */