UVA 10075 Arilines

点击打开链接

题意:

最短路。。。。

披着三维的外衣

 

 

 

 

 

#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const double eps=1e-10;//精度
const int INF=1<<29;
const double PI=acos(-1.0);
int dcmp(double x){//判断double等于0或。。。
	if(fabs(x)<eps)return 0;else return x<0?-1:1;
}
struct Point{
	double x,y,z;
	Point(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
};
typedef Point Vector;
Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y,a.z+b.z);}
Vector operator-(Point a,Point b){return Vector(a.x-b.x,a.y-b.y,a.z-b.z);}
Vector operator*(Vector a,double p){return Vector(a.x*p,a.y*p,a.z*p);}
Vector operator/(Vector a,double p){return Vector(a.x/p,a.y/p,a.z/p);}
bool operator==(Point a,Point b){return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0&&dcmp(a.z-b.z)==0;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y+a.z*b.z;}
double Length(Vector a){return sqrt(Dot(a,a));}
double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}
double torad(double deg){return deg/180*PI;}
void getcoord(double R,double lat ,double lng,double& x,double& y,double& z){
	lat=torad(lat);lng=torad(lng);
	x=R*cos(lat)*cos(lng);
	y=R*cos(lat)*sin(lng);
	z=R*sin(lat);
}
double DistanceToPlane(Point p,Point p0,Vector v){//点p到平面p0 n的距离
	return fabs(Dot(p-p0,v))/Length(v);//fabs取无向距离
}
Point GetPlaneProjection(Point p,Point p0,Vector v){//点p在平面p0 v上的投影
	double d=Dot(p-p0,v)/Length(v);
	return p+v*d;
}
Point LinePlaneIntersection(Point p1,Point p2,Point p0,Vector n){//直线p1 p2到平面p0 n的交点 交点必须唯一
	Vector v=p2-p1;
	double t=(Dot(n,p0-p1)/Dot(n,v));//Dot(n,v)==0时 平行或在平面上
	return p1+v*t;
}
Vector Cross(Vector a,Vector b){//三维叉积 右手定则
	return Vector(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
double Area2(Point a,Point b,Point c){return Length(Cross(b-a,c-a));}
bool PointInTri(Point p,Point p0,Point p1,Point p2){//点p在三角形p0 p1 p2中
	double area1=Area2(p,p0,p1);
	double area2=Area2(p,p1,p2);
	double area3=Area2(p,p2,p0);
	return dcmp(area1+area2+area3-Area2(p0,p1,p2))==0;
}
bool TriSegIntersection(Point a,Point b,Point c,Point p,Point q,Point& Intersection){//三角形abc是否和线段p q相交 Intersection为交点
	Vector n=Cross(b-a,c-a);
	if(dcmp(Dot(n,q-p))==0) return false;//三角形和直线平行或共面
	else{//三角形和直线平行或共面
		double t=Dot(n,a-p)/Dot(n,q-p);
		if(dcmp(t)<0||double(t-1)>0) return false;//交点不在线段AB上
		Intersection=p+(q-p)*t;
		return PointInTri(Intersection,a,b,c);
	}
}
double DistanceToLine(Point p,Point a,Point b){//点p到直线ab的距离
	Vector v1=b-a,v2=p-a;
	return Length(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(Point p,Point a,Point b){
	if(a==b) return Length(p-a);
	Vector v1=b-a,v2=p-a,v3=p-b;
	if(dcmp(Dot(v1,v2))<0) return Length(v2);
	else if(dcmp(Dot(v1,v3))>0) return Length(v3);
	else return Length(Cross(v1,v2))/Length(v1);
}
//......
//................................
//................................

int n,m,Q;
struct node{
	string name;
	double x,y;
}hehe[120];
int find(string name){
	for(int i=1;i<=n;i++)if(name==hehe[i].name)
		return i;
	return -1;
}
typedef pair<int,int>pii;  
vector<pii>G[110];
bool vis[110];
int d[110];
priority_queue<pii, vector<pii>, greater<pii> > q;
void Dijkstra(int src){  
    memset(vis, 0, sizeof(vis));  
    for(int i=1; i<=n; ++i) d[i] = INF;  
    d[src] = 0;  
    q.push(make_pair(d[src], src));  
    while(!q.empty()){  
        pii t = q.top(); q.pop();  
        int u = t.second;  
        if(vis[u]) continue;  
        vis[u] = true;  
        for(int v=0; v<G[u].size(); ++v)if(d[G[u][v].first] > d[u]+G[u][v].second){  
            d[G[u][v].first] = d[u]+G[u][v].second;  
            q.push(make_pair(d[G[u][v].first], G[u][v].first));
		}
	}
} 

int main()
{
	int cas=1;
	while(scanf("%d%d%d",&n,&m,&Q)&&n&&m&&Q){
		if(cas!=1) printf("\n");
		printf("Case #%d\n",cas++);
		for(int i=1;i<=n;i++){
			G[i].clear();
			cin>>hehe[i].name>>hehe[i].x>>hehe[i].y;
		}
		string a,b;
		for(int i=0;i<m;i++){
			cin>>a>>b;
			int u=find(a);
			int v=find(b);
			Point p,q;
			getcoord(6378,hehe[u].x,hehe[u].y,p.x,p.y,p.z);
			getcoord(6378,hehe[v].x,hehe[v].y,q.x,q.y,q.z);
			double ang=asin(Length(p-q)/2/6378)*2;
			int w=floor(ang*6378+0.5);
			G[u].push_back(make_pair(v,w));
			//G[v].push_back(make_pair(u,w));
		}
		for(int i=0;i<Q;i++){
			cin>>a>>b;
			int u=find(a);
			int v=find(b);
			Dijkstra(u);
			if(d[v]!=INF)printf("%d km\n",d[v]);
			else printf("no route exists\n");
		}
	}
    return 0;
}


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值