标签:str 分享 who 之间 cond bsp 如何 object tin
Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver.
You are describing a routine that optimizes the white bird‘s strategy to defeat a pig (enemy) by hitting an egg bomb. The white bird follows a parabolic trajectory from the initial position, and it can vertically drop egg bombs on the way.
In order to make it easy to solve, the following conditions hold for the stages.
The acceleration of gravity is 9.8 {\rm m/s^2}. Gravity exerts a force on the objects in the decreasing direction of y-coordinate.
A dataset follows the format shown below:
NVXY
L_1B_1R_1T_1
...
L_NB_NR_NT_N
All inputs are integer.
(0 \leq N \leq 50, 0 \leq V \leq 50, 0 \leq X, Y \leq 300, X \neq 0)
for 1 \leq i \leq N,
(0 \leq L_i, B_i, R_i, T_i \leq 300)
It is guaranteed that the answer remains unaffected by a change of L_i, B_i, R_i and T_i in 10^{-6}.
Yes/No
You should answer whether the white bird can drop an egg bomb toward the pig.
0 7 3 1
Yes
1 7 3 1 1 1 2 2
No
1 7 2 2 0 1 1 2
No
1 #include <cstdio> 2 #include <cmath> 3 4 using namespace std; 5 6 const double EPS=1e-10; 7 const int MAX_N=1000; 8 const double g=9.8; 9 int N,V,X,Y; 10 int L[MAX_N], B[MAX_N], R[MAX_N], T[MAX_N]; 11 12 double calc(double vy, double t) 13 { 14 return vy*t-g*t*t/2; 15 } 16 17 int cmp(double lb, double ub, double a) 18 { 19 return a<lb+EPS ? -1 : a>ub-EPS ? 1 : 0; 20 } 21 22 bool check(double qx, double qy) 23 { 24 double a=g*g/4, b=g*qy-V*V, c=qx*qx+qy*qy; 25 double D=b*b-4*a*c; 26 if (D<0 && D>-EPS) D=0; 27 if (D<0) return false; 28 for (int d=-1; d<=1; d+=2) 29 { 30 double t2=(-b+d*sqrt(D))/(2*a); 31 if (t2<=0) continue; 32 double t=sqrt(t2); 33 double vx=qx/t, vy=(qy+g*t*t/2)/t; 34 double yt=calc(vy, X/vx); 35 if (yt<Y-EPS) continue; 36 bool ok=true; 37 for (int i=0; i<N; i++) 38 { 39 if (L[i]>=X) continue; 40 if (R[i]==X && Y<=T[i] && B[i]<=yt) ok=false; 41 int yL=cmp(B[i], T[i], calc(vy, L[i]/vx)); 42 int yR=cmp(B[i], T[i], calc(vy, R[i]/vx)); 43 int xH=cmp(L[i], R[i], vx*(vy/g)); 44 int yH=cmp(B[i], T[i], calc(vy, vy/g)); 45 if (xH==0 && yH>=0 && yL<0) ok=false; 46 if (yL*yR<=0) ok=false; 47 } 48 if (ok) return true; 49 } 50 return false; 51 } 52 53 int min(int x, int y) 54 { 55 if (x<y) return x; 56 return y; 57 } 58 59 int main() 60 { 61 scanf("%d %d %d %d", &N, &V, &X, &Y); 62 for (int i=0; i<N; i++) 63 { 64 scanf("%d %d %d %d", &L[i], &B[i], &R[i], &T[i]); 65 } 66 for (int i=0; i<N; i++) 67 { 68 R[i]=min(R[i], X); 69 } 70 bool ok=check(X,Y); 71 for (int i=0; i<N; i++) 72 { 73 ok |= check(L[i], T[i]); 74 ok |= check(R[i], T[i]); 75 } 76 puts(ok ? "Yes" : "No"); 77 }
标签:str 分享 who 之间 cond bsp 如何 object tin
原文地址:https://www.cnblogs.com/Ymir-TaoMee/p/9791135.html