按经纬度设计经过中国所有省会、直辖市及香港、澳门、台北的最短路线方案

真不知道该如何解决,望高人指点!~~谢谢。... 真不知道该如何解决,望高人指点!~~谢谢。 展开
 我来答
匿名用户
2010-06-01
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 数学建模
{
class city
{
public string name;
public double JingDu;
public double WeiDu;

public city()
{
}

}
class Program
{
static public double juli(double Ajing, double Awei, double Bjing, double Bwei)
{
double d;

d=(111.12*Math.Cos(1/(Math.Sin(Awei)*Math.Sin(Bwei)+ Math.Cos(Awei)*Math.Cos(Bwei)*Math.Cos(Bjing-Ajing))));
return d;
}//定义一个一已知两城市经纬度算出距离的函数

static void Main(string[] args)
{
int i,j, k,number=32,p=0;
int[] num=new int[32];
int[] travel = new int[32];
double[,] juli = new double[33, 33];
double min=0;
city[] a=new city[33];
int x=0;
const double pi=3.14;

for (; x < 33;x++ )
a[x] = new city();
a[0].name = "哈尔滨"; a[4].JingDu = 126.41; a[4].WeiDu = 45.45;
a[1].name = "上海"; a[1].JingDu = 121.29; a[1].WeiDu = 31.14;
a[2].name = "天津"; a[2].JingDu = 117.11; a[2].WeiDu = 39.09;
a[3].name = "重庆"; a[3].JingDu = 106.32; a[3].WeiDu = 29.32;
a[4].name = "北京"; a[0].JingDu = 116.28; a[0].WeiDu = 39.54;
a[5].name = "长春"; a[5].JingDu = 125.19; a[5].WeiDu = 43.52;
a[6].name = "沈阳"; a[6].JingDu = 123.24; a[6].WeiDu = 41.50;
a[7].name = "呼和浩特"; a[7].JingDu = 111.48; a[7].WeiDu = 40.49;
a[8].name = "石家庄"; a[8].JingDu = 114.28; a[8].WeiDu = 38.02;
a[9].name = "太原"; a[9].JingDu = 112.34; a[9].WeiDu = 37.52;
a[10].name = "济南"; a[10].JingDu = 117; a[10].WeiDu = 36.38;
a[11].name = "郑州"; a[11].JingDu = 113.42; a[11].WeiDu = 34.48;
a[12].name = "西安"; a[12].JingDu = 108.54; a[12].WeiDu = 34.16;
a[13].name = "兰州"; a[13].JingDu = 103.49; a[13].WeiDu = 36.03;
a[14].name = "银川"; a[14].JingDu = 106.16; a[14].WeiDu = 38.20;
a[15].name = "西宁"; a[15].JingDu = 101.45; a[15].WeiDu = 36.38;
a[16].name = "乌鲁木齐"; a[16].JingDu = 87.36; a[16].WeiDu = 43.38;
a[17].name = "合肥"; a[17].JingDu = 117.18; a[17].WeiDu = 31.51;
a[18].name = "南京"; a[18].JingDu = 118.50; a[18].WeiDu = 32.02;
a[19].name = "杭州"; a[19].JingDu = 120.09; a[19].WeiDu = 30.14;
a[20].name = "长沙"; a[20].JingDu = 113; a[20].WeiDu = 28.11;
a[21].name = "南昌"; a[21].JingDu = 115.52; a[21].WeiDu = 28.41;
a[22].name = "武汉"; a[22].JingDu = 114.21; a[22].WeiDu = 30.37;
a[23].name = "成都"; a[23].JingDu = 104.05; a[23].WeiDu = 30.39;
a[24].name = "贵阳"; a[24].JingDu = 106.42; a[24].WeiDu = 26.45;
a[25].name = "福州"; a[25].JingDu = 119.18; a[25].WeiDu = 26.05;
a[26].name = "台北"; a[26].JingDu = 121.31; a[26].WeiDu = 25.03;
a[27].name = "广州"; a[27].JingDu = 113.15; a[27].WeiDu = 23.08;
a[28].name = "海口"; a[28].JingDu = 110.20; a[28].WeiDu = 20.02;
a[29].name = "南宁"; a[29].JingDu = 108.20; a[29].WeiDu = 22.48;
a[30].name = "昆明"; a[30].JingDu = 102.41; a[30].WeiDu = 25;
a[31].name = "拉萨"; a[31].JingDu = 91.10; a[31].WeiDu = 29.40;
a[32].name = "香港"; a[32].JingDu = 114.10; a[32].WeiDu = 22.18;
Console.WriteLine("全国省会城市以及直辖市的经纬度");
for (i = 0; i <= 32; i++)
{
Console.WriteLine("{0}:东经{1},北纬{2}", a[i].name, a[i].JingDu, a[i].WeiDu);
a[i].JingDu=((a[i].JingDu-Convert.ToInt32(a[i].JingDu))/60)*pi/180+a[i].JingDu*pi/180;//将角度转变为弧度
a[i].WeiDu=((a[i].WeiDu-Convert.ToInt32(a[i].WeiDu))/60)*pi/180+a[i].WeiDu*pi/180;

}
for(j=0;j<=32;j++)
for (k = j+1; k <= 32; k++)
{
juli[k,j]=juli[j, k] = Program.juli(a[j].JingDu, a[j].WeiDu, a[k].JingDu, a[k].WeiDu);

}//循环算出任意两个不同城市间的距离
i=1;
num[0]=0;
while (number != 0)
{
min = juli[num[i-1], 0];
for (k = 0; k <= 32; k++)
{
if (Convert.ToBoolean(k = num[i]))
break;
if (juli[num[i-1], k] < min)
travel[p] = k;

}
p++;
i++;
number--;
}
Console.Write("最短路线为:\n{0}->",a[0].name);
for (i = 0; i <= 31; i++)
{
Console.Write("{0}->", a[travel[i]].name);
}
Console.ReadLine();
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式