File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < cmath>
2+ #include < cstdio>
3+ #include < vector>
4+ #include < iostream>
5+ #include < algorithm>
6+ using namespace std ;
7+
8+
9+ int main () {
10+ int n;
11+ cin >> n;
12+
13+ double a, b;
14+ cin >> a >> b;
15+ double shooterX[n+2 ];
16+ double shooterY[n+2 ];
17+ shooterX[0 ] = a;
18+ shooterY[0 ] = b;
19+
20+ double bomberX[n+2 ];
21+ double bomberY[n+2 ];
22+ for (int i = 0 ; i < n+1 ; i++){
23+ cin >> bomberX[i] >> bomberY[i];
24+ }
25+
26+ double vel = 20 ;
27+ double dist;
28+ int check = 1 ;
29+ for (int i = 0 ; i < n ; i++){
30+ dist = sqrt (pow (bomberX[i]-shooterX[i], 2 )+pow (bomberY[i]-shooterY[i], 2 ));
31+ if (dist < 10 ){
32+ check=0 ;
33+ cout << i << endl;
34+ printf (" %.2f" , dist);
35+ break ;
36+ }
37+ shooterX[i+1 ]=shooterX[i]+vel*((bomberX[i]-shooterX[i])/dist);
38+ shooterY[i+1 ]=shooterY[i]+vel*((bomberY[i]-shooterY[i])/dist);
39+ }
40+ // for(int i = 0 ; i <= n+1; i++){
41+ // cout << shooterX[i] << " " << shooterY[i] << endl;
42+ // }
43+ if (check == 1 )
44+ {
45+ cout << -1 << endl;
46+ }
47+ return 0 ;
48+ }
You can’t perform that action at this time.
0 commit comments