forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alldifferentdirections.cpp
69 lines (58 loc) · 1.75 KB
/
alldifferentdirections.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
using namespace std;
double dist(double x1, double y1, double x2, double y2) {
return sqrt(pow(x1-x2,2) + pow(y1-y2,2));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
while(cin >> n && n != 0) {
vector<pair<double, double>> destinations;
for(int i = 0; i < n; i++) {
double x, y;
double angle;
cin >> x >> y;
string directions;
getline(cin, directions);
stringstream ss(directions);
string direction;
double dist;
while(ss >> direction && ss >> dist) {
if(direction == "start") {
angle = dist;
}
if(direction == "walk") {
x += dist * cos(angle * M_PI/180);
y += dist * sin(angle * M_PI/180);
}
if(direction == "turn") {
angle += dist;
}
}
pair<double, double> p = {x, y};
destinations.push_back(p);
}
double avgx = 0;
double avgy = 0;
for(auto i : destinations) {
avgx += i.first;
avgy += i.second;
}
avgx /= destinations.size();
avgy /= destinations.size();
double maxdist = 0;
for(int i = 0; i < destinations.size(); i++) {
double disthere = dist(avgx, avgy, destinations[i].first, destinations[i].second);
if(disthere > maxdist) {
maxdist = disthere;
}
}
cout << fixed;
cout.precision(4);
cout << avgx << " " << avgy << " " << maxdist << endl;
}
}