#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int cmp(const double &x)
{
if (fabs(x) < eps)
{
return 0;
}
if (x > 0)
{
return 1;
}
return -1;
}
inline double sqr(const double &x)
{
return x*x;
}
class Point
{
public:
double x, y;
Point() {}
Point(const double &a, const double &b) :x(a), y(b) {}
void input()
{
cin >> x >> y;
}
friend Point operator+(const Point &a, const Point &b)
{
return Point(a.x + b.x, a.y + b.y);
}
friend Point operator-(const Point &a, const Point &b)
{
return Point(a.x - b.x, a.y - b.y);
}
friend bool operator==(const Point &a, const Point &b)
{
return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0;
}
friend Point operator*(const Point &a, const double &b)
{
return Point(a.x*b, a.y*b);
}
friend Point operator*(const double &a, const Point &b)
{
return Point(b.x*a, b.y*a);
}
friend Point operator/(const Point &a, const double &b)
{
return Point(a.x / b, a.y / b);
}
double norm()
{
return sqrt(sqr(x) + sqr(y));
}
};
double det(const Point &a, const Point &b)
{
return a.x*b.y - a.y * b.x;
}
double dot(const Point &a, const Point &b)
{
return a.x*b.x + a.y * b.y;
}
double dist(const Point &a, const Point &b)
{
return (a - b).norm();
}
Point rotate_point(const Point&p, const double &A)
{
double tx = p.x, ty = p.y;
return Point(tx*cos(A) - ty*sin(A), tx*sin(A) + ty*cos(A));
}
class Line
{
public:
Point a, b;
Line() {}
Line(const Point&x, const Point &y) :a(x), b(y) {}
Line point_make_line(const Point &a, const Point &b)
{
return Line(a, b);
}
};
double dist_point_segment(const Point &p, const Point &s, const Point &t)
{
if (cmp(dot(p - s, t - s))<0)
{
return (p - s).norm();
}
if (cmp(dot(p - t, s - t)) < 0)
{
return (p - t).norm();
}
return fabs(det(s - p, t - p) / dist(s, t));
}
void PointProjLine(const Point &p, const Point &s, const Point&t, Point &cp)
{
double r = dot((t - s), (p - s)) / dot(t - s, t - s);
cp = s + r*(t - s);
}
bool PointOnSegment(const Point&p, const Point &s, const Point &t)
{
return cmp(det(p - s, t - s)) == 0 && cmp(dot(p - s, p - t)) <= 0;
}
bool parallel(const Line&a, const Line&b)
{
return !cmp(det(a.a - a.b, b.a - b.b));
}
bool line_make_point(const Line &a, const Line&b, Point &res)
{
if (parallel(a, b)) return false;
double s1 = det(a.a - b.a, b.b - b.a);
double s2 = det(a.b - b.a, b.b - b.a);
res = (s1*a.b - s2*a.a) / (s1 - s2);
return true;
}
Line move_d(const Line &a, const double &len)
{
Point d = a.b - a.a;
d = d / d.norm();
d = rotate_point(d, pi / 2);
return Line(a.a + d*len, a.b + d*len);
}
map<string, double>getCompass()
{
map<string, double>Map;
Map.insert({ "N",0.0 });
Map.insert({ "NbE",11.25 });
Map.insert({ "NNE",22.5 });
Map.insert({ "NEbN", 33.75 });
Map.insert({ "NE",45 });
Map.insert({ "NEbE",56.25 });
Map.insert({ "ENE", 67.5 });
Map.insert({ "EbN", 78.75 });
Map.insert({ "E", 90 });
Map.insert({ "EbS", 101.25 });
Map.insert({ "ESE", 112.5 });
Map.insert({ "SEbE", 123.75 });
Map.insert({ "SE", 135 });
Map.insert({ "SEbS", 146.25 });
Map.insert({ "SSE", 157.5 });
Map.insert({ "SbE",168.75 });
Map.insert({ "S", 180 });
Map.insert({ "SbW", 191.25 });
Map.insert({ "SSW", 202.5 });
Map.insert({ "SWbS", 213.75 });
Map.insert({ "SW",225 });
Map.insert({ "SWbW", 236.25 });
Map.insert({ "WSW",247.5 });
Map.insert({ "WbS",258.75 });
Map.insert({ "W", 270 });
Map.insert({ "WbN", 281.25 });
Map.insert({ "WNW",292.5 });
Map.insert({ "NWbW",303.75 });
Map.insert({ "NW", 315 });
Map.insert({ "NWbN",326.25 });
Map.insert({ "NNW",337.5 });
Map.insert({ "NbW", 348.75 });
return Map;
}
double AngelToRadian(const double &angel)
{
return angel*pi / 180.0;
}
Point getTreasure(map<string,double>compass,const vector<pair<string, double>>&pos_dist)
{
Point treasure{0.0,0.0};
for (size_t i = 0; i < pos_dist.size(); i++)
{
double angel=AngelToRadian(compass[pos_dist[i].first]);
treasure.x += pos_dist[i].second*sin(angel);
treasure.y += pos_dist[i].second*cos(angel);
}
return treasure;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
auto compass = getCompass();
int n;
while (cin >> n&&n)
{
vector<pair<string, double>>pos_dist(n);
for (int i = 0; i < n; i++)
{
cin >> pos_dist[i].first >> pos_dist[i].second;
}
auto treasure = getTreasure(compass, pos_dist);
double offset; cin >> offset;//偏移量
double minimum = 1000000000.0;
Point origin(0, 0);
for (size_t i = 0; i < pos_dist.size(); i++)
{
Point another = origin;
double angel = AngelToRadian(compass[pos_dist[i].first]-offset);
another.x += pos_dist[i].second*sin(angel);
another.y += pos_dist[i].second*cos(angel);
minimum = min(minimum,dist_point_segment(treasure, origin, another));
origin = another;
}
printf("%.2lf\n", minimum);
}
return 0;
}
uva_10553_Treasure Map
最新推荐文章于 2018-04-29 12:33:37 发布