add csharp examples (#10)
This commit is contained in:
committed by
Aditya Bhargava
parent
c3396b8b0a
commit
62ed616954
2
08_greedy_algorithms/csharp/01_set_covering/.gitignore
vendored
Normal file
2
08_greedy_algorithms/csharp/01_set_covering/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
08_greedy_algorithms/csharp/01_set_covering/.vscode/launch.json
vendored
Normal file
23
08_greedy_algorithms/csharp/01_set_covering/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_set_covering.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
08_greedy_algorithms/csharp/01_set_covering/.vscode/tasks.json
vendored
Normal file
16
08_greedy_algorithms/csharp/01_set_covering/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
37
08_greedy_algorithms/csharp/01_set_covering/Program.cs
Normal file
37
08_greedy_algorithms/csharp/01_set_covering/Program.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var statesNeeded = new HashSet<string> { "mt", "wa", "or", "id", "nv", "ut", "ca", "az" };
|
||||
var stations = new Dictionary<string, HashSet<string>>();
|
||||
stations.Add("kone", new HashSet<string> { "id", "nv", "ut" });
|
||||
stations.Add("ktwo", new HashSet<string> { "wa", "id", "mt" });
|
||||
stations.Add("kthree", new HashSet<string> { "or", "nv", "ca" });
|
||||
stations.Add("kfour", new HashSet<string> { "nv", "ut" });
|
||||
stations.Add("kfive", new HashSet<string> { "ca", "az" });
|
||||
var finalStations = new HashSet<string>();
|
||||
while (statesNeeded.Any())
|
||||
{
|
||||
string bestStation = null;
|
||||
var statesCovered = new HashSet<string>();
|
||||
foreach (var station in stations)
|
||||
{
|
||||
var covered = new HashSet<string>(statesNeeded.Intersect(station.Value));
|
||||
if (covered.Count > statesCovered.Count){
|
||||
bestStation = station.Key;
|
||||
statesCovered = covered;
|
||||
}
|
||||
}
|
||||
statesNeeded.RemoveWhere(s => statesCovered.Contains(s));
|
||||
finalStations.Add(bestStation);
|
||||
}
|
||||
Console.WriteLine(string.Join(", ", finalStations));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
08_greedy_algorithms/csharp/01_set_covering/project.json
Normal file
19
08_greedy_algorithms/csharp/01_set_covering/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
08_greedy_algorithms/csharp/01_set_covering/project.lock.json
Normal file
6598
08_greedy_algorithms/csharp/01_set_covering/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user