Skip to content

Commit a01fd63

Browse files
authored
Merge pull request #250 from ikesnowy/Day103
Day103
2 parents 83fa324 + d3857e9 commit a01fd63

File tree

17 files changed

+515
-11
lines changed

17 files changed

+515
-11
lines changed

1 Fundamental/1.5/1.5.1/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@ class Program
1919
static void Main(string[] args)
2020
{
2121
string[] input = "9-0 3-4 5-8 7-2 2-1 5-7 0-3 4-2".Split(' ');
22-
QuickFindUF quickFind = new QuickFindUF(10);
22+
var quickFind = new QuickFindUF(10);
2323

2424
foreach (string s in input)
2525
{
26-
int totalArrayVisit = 0;
26+
quickFind.ResetArrayCount();
27+
2728
string[] numbers = s.Split('-');
2829
int p = int.Parse(numbers[0]);
2930
int q = int.Parse(numbers[1]);
3031

31-
totalArrayVisit += quickFind.Union(p, q);
3232
int[] id = quickFind.GetID();
33+
quickFind.Union(p, q);
3334
foreach (int root in id)
3435
{
3536
Console.Write(root + " ");
3637
}
37-
Console.WriteLine("数组访问:" + totalArrayVisit);
38+
Console.WriteLine("数组访问:" + quickFind.ArrayVisitCount);
3839
}
3940
}
4041
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F852B8C3-4743-4E03-9711-C51970F2D9CA}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>_1._5._2</RootNamespace>
10+
<AssemblyName>1.5.2</AssemblyName>
11+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Program.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="App.config" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<ProjectReference Include="..\UnionFind\UnionFind.csproj">
53+
<Project>{b18b7737-dfdd-4319-ab4f-db6ac3352a3d}</Project>
54+
<Name>UnionFind</Name>
55+
</ProjectReference>
56+
</ItemGroup>
57+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58+
</Project>

1 Fundamental/1.5/1.5.2/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
5+
</startup>
6+
</configuration>

1 Fundamental/1.5/1.5.2/Program.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnionFind;
7+
8+
namespace _1._5._2
9+
{
10+
/*
11+
* 1.5.2
12+
*
13+
* 使用 quick-union 算法(请见 1.5.2.3 节代码框)完成练习 1.5.1。
14+
* 另外,在处理完输入的每对整数之后画出 id[] 数组表示的森林。
15+
*
16+
*/
17+
class Program
18+
{
19+
static void Main(string[] args)
20+
{
21+
string[] input = "9-0 3-4 5-8 7-2 2-1 5-7 0-3 4-2".Split(' ');
22+
var quickUnion = new QuickUnionUF(10);
23+
24+
foreach (string s in input)
25+
{
26+
quickUnion.ResetArrayCount();
27+
string[] numbers = s.Split('-');
28+
int p = int.Parse(numbers[0]);
29+
int q = int.Parse(numbers[1]);
30+
31+
quickUnion.Union(p, q);
32+
int[] parent = quickUnion.GetParent();
33+
for (int i = 0; i < parent.Length; ++i)
34+
{
35+
if (parent[i] == i)
36+
{
37+
Console.WriteLine(i);
38+
for (int j = 0; j < parent.Length; ++j)
39+
{
40+
if (parent[j] == i && j != i)
41+
{
42+
Console.WriteLine(" |---- " + j);
43+
}
44+
}
45+
}
46+
}
47+
Console.WriteLine("数组访问:" + quickUnion.ArrayVisitCount);
48+
}
49+
}
50+
}
51+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的一般信息由以下
6+
// 控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("1.5.2")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("1.5.2")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 会使此程序集中的类型
18+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19+
//请将此类型的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("f852b8c3-4743-4e03-9711-c51970f2d9ca")]
24+
25+
// 程序集的版本信息由下列四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 生成号
30+
// 修订号
31+
//
32+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33+
// 方法是按如下所示使用“*”: :
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{664C8D2B-353E-4749-B9BF-5110FCBC1B82}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>_1._5._3</RootNamespace>
10+
<AssemblyName>1.5.3</AssemblyName>
11+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Program.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="App.config" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<ProjectReference Include="..\UnionFind\UnionFind.csproj">
53+
<Project>{b18b7737-dfdd-4319-ab4f-db6ac3352a3d}</Project>
54+
<Name>UnionFind</Name>
55+
</ProjectReference>
56+
</ItemGroup>
57+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58+
</Project>

1 Fundamental/1.5/1.5.3/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
5+
</startup>
6+
</configuration>

1 Fundamental/1.5/1.5.3/Program.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnionFind;
7+
8+
namespace _1._5._3
9+
{
10+
/*
11+
* 1.5.3
12+
*
13+
* 使用加权 quick-union 算法(请见算法 1.5)完成练习 1.5.1 。
14+
*
15+
*/
16+
class Program
17+
{
18+
static void Main(string[] args)
19+
{
20+
string[] input = "9-0 3-4 5-8 7-2 2-1 5-7 0-3 4-2".Split(' ');
21+
var weightedQuickUnion = new WeightedQuickUnionUF(10);
22+
23+
foreach (string s in input)
24+
{
25+
weightedQuickUnion.ResetArrayCount();
26+
string[] numbers = s.Split('-');
27+
int p = int.Parse(numbers[0]);
28+
int q = int.Parse(numbers[1]);
29+
30+
weightedQuickUnion.Union(p, q);
31+
int[] parent = weightedQuickUnion.GetParent();
32+
for (int i = 0; i < parent.Length; ++i)
33+
{
34+
if (parent[i] == i)
35+
{
36+
Console.WriteLine(i);
37+
for (int j = 0; j < parent.Length; ++j)
38+
{
39+
if (parent[j] == i && j != i)
40+
{
41+
Console.WriteLine(" |---- " + j);
42+
}
43+
}
44+
}
45+
}
46+
Console.WriteLine("数组访问:" + weightedQuickUnion.ArrayVisitCount);
47+
}
48+
}
49+
}
50+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的一般信息由以下
6+
// 控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("1.5.3")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("1.5.3")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 会使此程序集中的类型
18+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19+
//请将此类型的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("664c8d2b-353e-4749-b9bf-5110fcbc1b82")]
24+
25+
// 程序集的版本信息由下列四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 生成号
30+
// 修订号
31+
//
32+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33+
// 方法是按如下所示使用“*”: :
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)