uva_10553_Treasure Map

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值