题意不难理解,仔细看题吧,就不说题意了
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const double PI=acos(-1.0); const double g=9.8; double V[205]; int main() { //freopen("in.txt","r",stdin); int n; while(scanf("%d",&n),n) { double H,L1,R1,L2,R2; memset(V,0,sizeof(V)); scanf("%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2); for(int i=0; i<n; i++) scanf("%lf",&V[i]); if(L2<=L1 && R2>=R1) printf("0 "); else { int ans=0; double add=PI/1000; //一开始我是另add=0.001,虽然比PI/1000还小,然而无限wa。可能是样例所要求弧度是PI平均分割的,0.001精读比PI/1000小,例如(没验证),0.003不能打到敌方,而0.00314159....可以,但是0.004也不能打到敌方。 for(double i=-PI/2; i<PI/2; i+=add) { int cou=0; for(int j=0;j<n;j++) { double Vx0=V[j]*cos(i); double Vy0=V[j]*sin(i); double Vy=sqrt(2*g*H+Vy0*Vy0); double t=(Vy-Vy0)/g; double x=Vx0*t; if(x>=L2 && x<=R2) { cou=0; break; } if(x>=L1 && x<=R1) cou++; } ans=ans>cou? ans:cou; } printf("%d ",ans); } } return 0; }