資源簡介
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?????????????{
????????????????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?????????????{
????????????????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?????????????{
????????????????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個文件信息
評論
共有 條評論