http://acm.hdu.edu.cn/showproblem.php?pid=4445
要求发射的炮弹在都不落在friendly tank区域的条件下落在enemy tank区域的最多数目。
直接暴力枚举角度。。
#include <stdio.h> #include <iostream> #include <map> #include <set> #include <bitset> #include <list> #include <stack> #include <vector> #include <math.h> #include <string.h> #include <queue> #include <string> #include <stdlib.h> #include <algorithm> //#define LL __int64 #define LL long long #define eps 1e-9 const double PI = acos(-1.0); const double g = 9.8; using namespace std; int n; double l1,r1,l2,r2,h; double v[210]; int solve(double a) { int cnt = 0; for(int i = 0; i < n; i++) { double Vy0 = v[i] * sin(a); double Vx0 = v[i] * cos(a); double Vy = sqrt(Vy0*Vy0 + 2*g*h); double t = (Vy - Vy0)/g; double s = t*Vx0; if(s >= l2 && s <= r2) return 0; if(s >= l1 && s <= r1) cnt++; } return cnt; } int main() { while(~scanf("%d",&n)&&n) { scanf("%lf %lf %lf %lf %lf",&h,&l1,&r1,&l2,&r2); for(int i = 0; i < n; i++) scanf("%lf",&v[i]); double add = PI/1000.0; int ans = 0; for(double i = -PI/2; i <= PI/2; i += add) { ans = max(ans,solve(i)); } printf("%d\n",ans); } return 0; }
时间: 2024-12-26 08:52:22