Skip to content

Commit 184b24f

Browse files
Create Solution.cpp
1 parent 5b59876 commit 184b24f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Assignment 2/Solution.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

0 commit comments

Comments
 (0)