bastien.monsarrat 7 vuotta sitten
vanhempi
commit
1385acc21a
4 muutettua tiedostoa jossa 203 lisäystä ja 12 poistoa
  1. 18 12
      Adv2018.sln
  2. 12 0
      D6.Bonus/D6.Bonus.csproj
  3. 165 0
      D6.Bonus/Program.cs
  4. 8 0
      D6.Bonus/Properties/launchSettings.json

+ 18 - 12
Adv2018.sln

@@ -3,29 +3,31 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
 VisualStudioVersion = 15.0.28307.136
 MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D01.1", "D1.1\D01.1.csproj", "{75F7258F-26A1-40DD-BF7C-68BE0A79AD46}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D01.1", "D1.1\D01.1.csproj", "{75F7258F-26A1-40DD-BF7C-68BE0A79AD46}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D01.2", "D1.2\D01.2.csproj", "{95858808-D3A8-4878-BAA1-48E85CE7B966}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D01.2", "D1.2\D01.2.csproj", "{95858808-D3A8-4878-BAA1-48E85CE7B966}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D02.1", "D2.1\D02.1.csproj", "{9EC3265A-AFE8-43BB-9720-5304D758545E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D02.1", "D2.1\D02.1.csproj", "{9EC3265A-AFE8-43BB-9720-5304D758545E}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D02.2", "D2.2\D02.2.csproj", "{236C4ABF-E4BB-4878-9128-8B18F59DC367}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D02.2", "D2.2\D02.2.csproj", "{236C4ABF-E4BB-4878-9128-8B18F59DC367}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D03.1", "D3.1\D03.1.csproj", "{F261A83D-185D-4657-9C01-0A6E0F5F7EA6}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D03.1", "D3.1\D03.1.csproj", "{F261A83D-185D-4657-9C01-0A6E0F5F7EA6}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D03.2", "D3.2\D03.2.csproj", "{177DB14B-F338-447D-8653-3767192EA230}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D03.2", "D3.2\D03.2.csproj", "{177DB14B-F338-447D-8653-3767192EA230}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D04.1", "D4.1\D04.1.csproj", "{A52CF9DC-04B4-4636-A03E-F6DAF0AED13A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D04.1", "D4.1\D04.1.csproj", "{A52CF9DC-04B4-4636-A03E-F6DAF0AED13A}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D04.2", "D4.2\D04.2.csproj", "{AFA0D0FD-4FED-492A-BCC4-069CB222CBAA}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D04.2", "D4.2\D04.2.csproj", "{AFA0D0FD-4FED-492A-BCC4-069CB222CBAA}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D05.1", "D5.1\D05.1.csproj", "{0A753214-03DC-41AE-84BE-526C50C61A39}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D05.1", "D5.1\D05.1.csproj", "{0A753214-03DC-41AE-84BE-526C50C61A39}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D05.2", "D5.2\D05.2.csproj", "{C67118CD-EB45-454F-BE18-FBCE662FED26}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D05.2", "D5.2\D05.2.csproj", "{C67118CD-EB45-454F-BE18-FBCE662FED26}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D06.1", "D6.1\D06.1.csproj", "{DC62F9FB-7CF8-405E-A20F-6C0154CD437B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D06.1", "D6.1\D06.1.csproj", "{DC62F9FB-7CF8-405E-A20F-6C0154CD437B}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D06.2", "D6.2\D06.2.csproj", "{BC77C593-1F13-42F9-BC0D-D706CB87BE1A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D06.2", "D6.2\D06.2.csproj", "{BC77C593-1F13-42F9-BC0D-D706CB87BE1A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D6.Bonus", "D6.Bonus\D6.Bonus.csproj", "{A14766AE-E4A7-442E-809D-EE1938B3B1BF}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -81,6 +83,10 @@ Global
 		{BC77C593-1F13-42F9-BC0D-D706CB87BE1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{BC77C593-1F13-42F9-BC0D-D706CB87BE1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{BC77C593-1F13-42F9-BC0D-D706CB87BE1A}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A14766AE-E4A7-442E-809D-EE1938B3B1BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A14766AE-E4A7-442E-809D-EE1938B3B1BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A14766AE-E4A7-442E-809D-EE1938B3B1BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A14766AE-E4A7-442E-809D-EE1938B3B1BF}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 12 - 0
D6.Bonus/D6.Bonus.csproj

@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="System.Drawing.Common" Version="4.5.1" />
+  </ItemGroup>
+
+</Project>

+ 165 - 0
D6.Bonus/Program.cs

@@ -0,0 +1,165 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+
+namespace D6.Bonus
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 2) return;
+            if (File.Exists(args[0]) == false) return;
+            if (int.TryParse(args[1], out int ceil) == false) return;
+
+            var coordinates = new List<((uint x, uint y) coord, bool isInfinite)>();
+            var file = File.OpenText(args[0]);
+
+            uint minXY = int.MaxValue;
+            uint maxXY = 0;
+
+            do
+            {
+                var line = file.ReadLine();
+                if (line == null) break;
+
+                var cl = line.Split(", ");
+                (uint x, uint y) xy = (uint.Parse(cl[0]), uint.Parse(cl[1]));
+
+                if (xy.x < minXY) minXY = xy.x;
+                if (xy.y < minXY) minXY = xy.y;
+                if (xy.x > maxXY) maxXY = xy.x;
+                if (xy.y > maxXY) maxXY = xy.y;
+
+                coordinates.Add((xy, false));
+            } while (true);
+
+            uint size = minXY + maxXY;
+
+            var area = new (int closest, int total)[size, size];
+
+            fillMapArea(size, coordinates, area);
+
+            flagPointOnEdges(size, coordinates);
+
+            GenerateBitMap(ceil, coordinates, size, area);
+        }
+
+        private static void GenerateBitMap(int ceil, List<((uint x, uint y) coord, bool isInfinite)> coordinates, uint size, (int closest, int total)[,] area)
+        {
+            var bmp = new Bitmap((int)size, (int)size);
+            Random r = new Random();
+            Dictionary<int, Color> Colors = new Dictionary<int, Color>();
+
+            for (var x = 0; x < size; x++)
+            {
+                for (var y = 0; y < size; y++)
+                {
+                    var id = area[x, y].closest;
+                    var total = area[x, y].total;
+
+                    if (Colors.ContainsKey(id) == false)
+                        Colors.Add(id, Color.FromArgb(coordinates.ElementAt(id).isInfinite ? 20 : 255, r.Next(0, 256), r.Next(0, 256), r.Next(0, 256)));
+
+                    if (coordinates.ElementAt(id).isInfinite && (x + y % 2) % 3 == 0) continue;
+
+                    bmp.SetPixel(x, y, Colors[id]);
+
+                    var c = bmp.GetPixel(x, y);
+                    if (total < ceil) bmp.SetPixel(x, y, Color.FromArgb((int)((c.R + 127) / 1.5), (int)((c.G + 127) / 1.5), (int)((c.B + 127) / 1.5)));
+                }
+            }
+
+            foreach (var coord in coordinates)
+            {
+                int x = (int)coord.coord.x;
+                int y = (int)coord.coord.y;
+                bmp.SetPixel(x, y, Color.Red);
+                bmp.SetPixel(x - 1, y, Color.Red);
+                bmp.SetPixel(x + 1, y, Color.Red);
+                bmp.SetPixel(x, y - 1, Color.Red);
+                bmp.SetPixel(x, y + 1, Color.Red);
+
+                bmp.SetPixel(x - 1, y - 1, Color.DarkRed);
+                bmp.SetPixel(x + 1, y - 1, Color.DarkRed);
+                bmp.SetPixel(x - 1, y + 1, Color.DarkRed);
+                bmp.SetPixel(x + 1, y + 1, Color.DarkRed);
+            }
+
+            bmp = new Bitmap(bmp, new Size((int)(size * 2), (int)(size * 2)));
+
+            bmp.Save("result.bmp");
+        }
+
+        private static int findMaxCoveredArea(List<((uint x, uint y) coord, bool isInfinite)> coordinates, int[] area)
+        {
+            int maxArea = 0;
+            for (int i = 0; i < area.Length; ++i)
+            {
+                if (coordinates.ElementAt(i).isInfinite) continue;
+
+                if (area[i] > maxArea) maxArea = area[i];
+            }
+
+            return maxArea;
+        }
+
+        private static void flagPointOnEdges(uint size, List<((uint x, uint y) coord, bool isInfinite)> coordinates)
+        {
+            for (uint i = 0; i < size; ++i)
+            {
+                var x0yi = GetClosest(coordinates, (0, i));
+                MarkInfinite(coordinates, x0yi.closest);
+
+                var xiy0 = GetClosest(coordinates, (i, 0));
+                MarkInfinite(coordinates, xiy0.closest);
+
+                var xsizeyi = GetClosest(coordinates, (size, i));
+                MarkInfinite(coordinates, xsizeyi.closest);
+
+                var xiysize = GetClosest(coordinates, (i, size));
+                MarkInfinite(coordinates, xiysize.closest);
+            }
+        }
+
+        private static void fillMapArea(uint size, List<((uint x, uint y) coord, bool isInfinite)> coordinates, (int closest, int total)[,] area)
+        {
+            for (uint x = 0; x < size; x++)
+            {
+                for (uint y = 0; y < size; y++)
+                {
+                    var closest = GetClosest(coordinates, (x, y));
+                    area[x,y] = closest;
+                }
+            }
+        }
+
+        private static (int closest, int total) GetClosest(List<((uint x, uint y) coord, bool isInfinite)> coordinates, (uint x, uint y) point)
+        {
+            int total = 0;
+            int lowest = int.MaxValue;
+            int lowestId = 0;
+            for (int i = 0; i < coordinates.Count; i++)
+            {
+                var (x, y) = coordinates[i].coord;
+                var manhattan = Math.Abs((int)point.x - (int)x) + Math.Abs((int)point.y - (int)y);
+                if (manhattan < lowest)
+                {
+                    lowest = manhattan;
+                    lowestId = i;
+                }
+                total += manhattan;
+            }
+            return (lowestId, total);
+        }
+
+        private static void MarkInfinite(List<((uint x, uint y) coord, bool isInfinite)> coordinates, int id)
+        {
+            var coord = coordinates[id];
+            coord.isInfinite = true;
+            coordinates[id] = coord;
+        }
+    }
+}

+ 8 - 0
D6.Bonus/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D6.Bonus": {
+      "commandName": "Project",
+      "commandLineArgs": "\"D:\\adv\\Adv2018\\D6.1\\input.txt\" 10000"
+    }
+  }
+}