资源简介
c#语言实现的邮局选址问题,具有图形化界面,非常适合初学者,代码清晰

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PostOfficeLocation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] X;//X坐标
int[] Y;//Y坐标
int count;//居民点数
double distance;//最短距离
string lineX;
string lineY;
private void button1_Click(object sender EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.Filter = “txt文件(*.txt)|*.txt“;
if (op.ShowDialog() == DialogResult.OK)
{
string fileName = op.FileName;
FileStream fs = new FileStream(fileNameFileMode.Open);
StreamReader sr = new StreamReader(fs);
count =Convert.ToInt32(sr.ReadLine());//读取居民点数
X = new int[count];
Y = new int[count];
lineX = sr.ReadLine();//读取Y坐标
lineY = sr.ReadLine();//读取X坐标
richTextBox1.Text += count.ToString() + ‘\n‘ + lineX + ‘\n‘ + lineY;
}
}
private void button2_Click(object sender EventArgs e)
{
for (int i = 0; i < count; i++)
{
X[i] = Convert.ToInt32(lineX.Split(‘ ‘)[i]);
Y[i] = Convert.ToInt32(lineY.Split(‘ ‘)[i]);
}
MergeSort(X 0 count - 1);
MergeSort(Y 0 count - 1);
int dx = X[count / 2];
int dy = Y[count / 2];
for (int i = 0; i < count; i++)
{
distance += Math.Sqrt((X[i] - dx) * (X[i] - dx) + (Y[i] - dy) * (Y[i] - dy));
}
label1.Text += distance.ToString();
}
#region 归并排序
private void MergeSort(int[] arry int first int last)
{
if (first < last)//退出条件
{
int mid = (first + last) / 2;
MergeSort(arry first mid);
MergeSort(arry mid + 1 last);
Sort(arry first mid last);
}
}
private void Sort(int[] arry int first int mid int last)
{
int indexA = first;
int indexB = mid + 1;
int[] temp = new int[last + 1];
int tempIndex = 0;
while (indexA <= mid && indexB <= last)
{
if (arry[indexA] <= arry[indexB])
{
temp[tempIndex] = arry[indexA];
tempIndex++;
indexA++;
}
else
{
temp[tempIndex] = arry[indexB];
tempIndex++;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 187 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\App.config
文件 50 2015-03-21 17:25 PostOfficeLocation\PostOfficeLocation\bin\Debug\input_assign01_01.txt
文件 10752 2015-03-21 17:22 PostOfficeLocation\PostOfficeLocation\bin\Debug\PostOfficeLocation.exe
文件 187 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\bin\Debug\PostOfficeLocation.exe.config
文件 26112 2015-03-21 17:22 PostOfficeLocation\PostOfficeLocation\bin\Debug\PostOfficeLocation.pdb
文件 22984 2015-04-09 16:03 PostOfficeLocation\PostOfficeLocation\bin\Debug\PostOfficeLocation.vshost.exe
文件 187 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\bin\Debug\PostOfficeLocation.vshost.exe.config
文件 490 2012-06-06 02:06 PostOfficeLocation\PostOfficeLocation\bin\Debug\PostOfficeLocation.vshost.exe.manifest
文件 3732 2015-03-21 19:04 PostOfficeLocation\PostOfficeLocation\Form1.cs
文件 3779 2015-03-21 17:18 PostOfficeLocation\PostOfficeLocation\Form1.Designer.cs
文件 5817 2015-03-21 17:18 PostOfficeLocation\PostOfficeLocation\Form1.resx
文件 851 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6971 2015-04-09 16:03 PostOfficeLocation\PostOfficeLocation\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 1186 2015-04-09 16:03 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.csproj.FileListAbsolute.txt
文件 975 2015-03-21 17:18 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.csproj.GenerateResource.Cache
文件 2143 2015-03-21 15:47 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.csprojResolveAssemblyReference.cache
文件 10752 2015-03-21 17:22 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.exe
文件 180 2015-03-21 17:18 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.Form1.resources
文件 26112 2015-03-21 17:22 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.pdb
文件 180 2015-03-21 15:47 PostOfficeLocation\PostOfficeLocation\obj\Debug\PostOfficeLocation.Properties.Resources.resources
文件 0 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 3815 2015-03-21 15:47 PostOfficeLocation\PostOfficeLocation\PostOfficeLocation.csproj
文件 530 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\Program.cs
文件 1356 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\Properties\AssemblyInfo.cs
文件 2884 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\Properties\Resources.Designer.cs
文件 5612 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\Properties\Resources.resx
文件 1101 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\Properties\Settings.Designer.cs
文件 249 2015-03-21 15:31 PostOfficeLocation\PostOfficeLocation\Properties\Settings.settings
............此处省略13个文件信息
相关资源
- C#实现的遗传算法类库
- 组合 算法 C# 背包问题
- c#语言实现K短路算法
- C# 视觉处理代码、神经网络和遗传算
- RSA算法实现加、解密
- 四叉树算法(KrigingCal)
- delta机器人运动学算法正向逆向求解
- C#多元线性回归算法
- 川大-- 数据结构考点精讲课程原版
- C#实现封装SPC过程能力工具类ProcessC
- 数据结构C#语言版
- 国密SM4算法 C#
- TIN生成算法实现.zip
- 网络安全LSB算法 采用C# 实现文字的隐
- C#数字图像处理算法典型
- 实验课排课系统
- C#数值计算算法编程
- 《C#数值计算算法编程》电子书+随书
- 数据结构上机程序合集
- 数据结构与算法C#
- c#四叉树算法实现
- A*逆向路径搜索算法C#代码以及地图文
- 武汉大学 C#数据结构与算法
- C#+ArcEngine面周边点抽稀源码
- 操作系统课设理发师问题,时间片轮
- 图像加密算法与实践
- 数据结构(C#语言描述-陈广-PPT及教材
- C#数字图像处理算法典型赵春江随书源
- 数据结构与算法:C#语言描述(中文)
- C#数据结构与算法
评论
共有 条评论