# uva 10553 Treasure Map (指南针偏差航海寻宝）

414人阅读 评论(0)

#include <bits/stdc++.h>
#include <iostream>

using namespace std;
const double eps = acos(-1.0);
int  n;
double num;
string str[32] = {"N", "NbE", "NNE", "NEbN", "NE", "NEbE", "ENE", "EbN", "E", "EbS", "ESE", "SEbE", "SE", "SEbS", "SSE",
"SbE", "S", "SbW", "SSW", "SWbS", "SW", "SWbW", "WSW", "WbS", "W", "WbN", "WNW", "NWbW", "NW", "NWbN", "NNW", "NbW"
};
struct Point
{
double x;double y;
Point(){};   //不加这一句，有的编译器会报错，no matching function for call to ...
Point(const double xx,const double yy)
{
x = xx; y = yy;
}
};
{
double x;
double y;
{
x = xx; y = yy;
}
};
map<string,double> direction;
void init()
{
for(int i = 0; i < 32; i++)
{
direction[str[i]] = eps*i/16;
}
}
{
string str0;
double num0;
for(int i = 0; i< n; i++)
{
cin >> str0 >> num0;

}
cin >> num;
num = num *eps /180;
}
double dis(Point p1,Point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
}
double dot(Point p0,Point p1,Point p2){  //p0p1点乘 p0p2;
return (p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);
}

struct line{
Point a,b;
line(const Point a0,const Point b0){a=a0;b=b0;}
double getdis(Point p){//点到线段的最小距离
if(dot(a,p,b)<0 || dot(b,p,a)<0) return min(dis(p,a),dis(p,b));
else{
double a0,b0,c0;
a0=a.y-b.y;
b0=b.x-a.x;
c0=a.x*b.y-b.x*a.y;
return fabs(a0*p.x+b0*p.y+c0)/sqrt(a0*a0+b0*b0);
}
}
};
void computing()
{
Point d(0,0),t(0,0),pre;
for(int i=0;i<n;i++){
}
double ans=dis(d,t);
for(int i=0;i<n;i++){
pre=t;
line l(pre,t);
ans=min(ans,l.getdis(d));
}
printf("%.2lf\n",ans);
}
int main()
{

init();
while(scanf("%d",&n)&&n)
{
computing();
}
return 0;
}


0
0

个人资料
• 访问：81859次
• 积分：2537
• 等级：
• 排名：第17030名
• 原创：175篇
• 转载：32篇
• 译文：0篇
• 评论：5条
文章分类
最新评论