题意:给一个坦克的高度,求炮弹能打中最多的数量
枚举角度,作为一名学霸虽然很快推出了公式,但是却没有考虑到,角度可以朝下的情况
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const double PI=acos(-1.0); 11 const double eps=1e-5; 12 const double g=9.8; 13 #define cl(a) memset(a,0,sizeof(a)) 14 #define ts printf("*****\n"); 15 const int MAXN=100006; 16 int cnt[MAXN],a; 17 int n,m,tt; 18 double H,L1,L2,R1,R2; 19 double v[MAXN]; 20 int fun(double an) 21 { 22 int ans=0; 23 for(int i=0;i<n;i++) 24 { 25 double vy=v[i]*sin(an); 26 double vx=v[i]*cos(an); 27 double vyy=sqrt(2*g*H+vy*vy); 28 double t=(vyy-vy)/g; 29 double x=t*vx; 30 if(x>=L2&&x<=R2)return 0; 31 if(L1<=x&&x<=R1) 32 { 33 ans++; 34 } 35 } 36 return ans; 37 } 38 int main() 39 { 40 int j,k; 41 #ifndef ONLINE_JUDGE 42 freopen("1.in","r",stdin); 43 #endif 44 int ca=0; 45 double i; 46 while(scanf("%d",&n)!=EOF) 47 { 48 if(n==0) break; 49 scanf("%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2); 50 for(int j=0;j<n;j++) 51 scanf("%lf",&v[j]); 52 int sum=0; 53 for(i=-PI/2;i<=PI/2;i+=(PI/1000)) 54 { 55 sum=max(sum,fun(i)); 56 } 57 printf("%d\n",sum); 58 } 59 return 0; 60 }
原文:http://www.cnblogs.com/cnblogs321114287/p/4438476.html