Skip to content

Commit

Permalink
Merge pull request #20 from fkdl0048/17-algospot-게임판-덮기
Browse files Browse the repository at this point in the history
Sovle: BOARDCOVER
  • Loading branch information
fkdl0048 authored Jan 11, 2024
2 parents 43e3465 + 47eac27 commit aa4cab3
Show file tree
Hide file tree
Showing 30 changed files with 470 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 2023/BOARDCOVER/BOARDCOVER.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions 2023/BOARDCOVER/BOARDCOVER.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BOARDCOVER", "BOARDCOVER.csproj", "{F82CED6D-BF45-4BE6-989F-BBADEB6BCB2D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F82CED6D-BF45-4BE6-989F-BBADEB6BCB2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F82CED6D-BF45-4BE6-989F-BBADEB6BCB2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F82CED6D-BF45-4BE6-989F-BBADEB6BCB2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F82CED6D-BF45-4BE6-989F-BBADEB6BCB2D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A23235E6-4196-4513-8249-34414E3E8A8B}
EndGlobalSection
EndGlobal
99 changes: 99 additions & 0 deletions 2023/BOARDCOVER/Board.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace BOARDCOVER
{
public class Board
{
private static readonly int[,,] coverType = new int[4, 3, 2]
{
{ { 0, 0 }, { 1, 0 }, { 0, 1 } },
{ { 0, 0 }, { 1, 0 }, { 1, 1 } },
{ { 0, 0 }, { 0, 1 }, { 1, 1 } },
{ { 0, 0 }, { 0, 1 }, { -1, 1 } }
};

public int Hight { get; }
public int Width { get; }
private readonly bool[,] _board;

public Board(int hight, int width)
{
Hight = hight;
Width = width;

_board = new bool[Hight, Width];

for (var i = 0; i < Hight; i++)
{
for (var j = 0; j < Width; j++)
{
_board[i, j] = true;
}
}
}

public void SetBlock(int y, int x)
{
_board[y, x] = false;
}

public void SetBlock(int x, int y, int type)
{
for (var i = 0; i < 3; i++)
{
var nx = x + coverType[type, i, 0];
var ny = y + coverType[type, i, 1];

SetBlock(ny, nx);
}
}

public bool IsBlock(int y, int x)
{
return _board[y, x];
}

public bool CanSetBlock(int x, int y, int type)
{
for (var i = 0; i < 3; i++)
{
var nx = x + coverType[type, i, 0];
var ny = y + coverType[type, i, 1];

if (nx < 0 || nx >= Width || ny < 0 || ny >= Hight)
{
return false;
}

if (!IsBlock(ny, nx))
{
return false;
}
}

return true;
}

public void RemoveBlock(int x, int y, int type)
{
for (var i = 0; i < 3; i++)
{
var nx = x + coverType[type, i, 0];
var ny = y + coverType[type, i, 1];

_board[ny, nx] = true;
}
}

public void Print()
{
for (var i = 0; i < Hight; i++)
{
for (var j = 0; j < Width; j++)
{
System.Console.Write(_board[i, j] ? '.' : '#');
}

System.Console.WriteLine();
}
}
}
}
52 changes: 52 additions & 0 deletions 2023/BOARDCOVER/BoardCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace BOARDCOVER
{
public class BoardCalculator
{
private readonly Board _board;

public BoardCalculator(Board board)
{
_board = board;
}

public (int y, int x) GetFirstBlock()
{
for (var i = 0; i < _board.Hight; i++)
{
for (var j = 0; j < _board.Width; j++)
{
if (_board.IsBlock(i, j))
{
return (i, j);
}
}
}

return (-1, -1);
}

public int GetCoverCount()
{
var (y, x) = GetFirstBlock();

if (y == -1)
{
return 1;
}

var count = 0;

for (var i = 0; i < 4; i++)
{
if (_board.CanSetBlock(x, y, i))
{
_board.SetBlock(x, y, i);
count += GetCoverCount();
_board.RemoveBlock(x, y, i);
}
}

return count;
}
}
}
37 changes: 37 additions & 0 deletions 2023/BOARDCOVER/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace BOARDCOVER
{
class Program
{
static void Main(string[] args)
{
var testCaseNumber = int.Parse(Console.ReadLine()!);

for (int i = 0; i < testCaseNumber; i++)
{
var input = Console.ReadLine()!.Split(' ');

var hight = int.Parse(input[0]);
var width = int.Parse(input[1]);

var board = new Board(hight, width);

for (var j = 0; j < hight; j++)
{
var line = Console.ReadLine()!;

for (var k = 0; k < width; k++)
{
if (line[k] == '#')
{
board.SetBlock(j, k);
}
}
}

var calculator = new BoardCalculator(board);

Console.WriteLine(calculator.GetCoverCount());
}
}
}
}
23 changes: 23 additions & 0 deletions 2023/BOARDCOVER/bin/Debug/net7.0/BOARDCOVER.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v7.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v7.0": {
"BOARDCOVER/1.0.0": {
"runtime": {
"BOARDCOVER.dll": {}
}
}
}
},
"libraries": {
"BOARDCOVER/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file added 2023/BOARDCOVER/bin/Debug/net7.0/BOARDCOVER.dll
Binary file not shown.
Binary file added 2023/BOARDCOVER/bin/Debug/net7.0/BOARDCOVER.exe
Binary file not shown.
Binary file added 2023/BOARDCOVER/bin/Debug/net7.0/BOARDCOVER.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net7.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "7.0.0"
}
}
}
61 changes: 61 additions & 0 deletions 2023/BOARDCOVER/obj/BOARDCOVER.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"format": 1,
"restore": {
"D:\\Algorithm\\2023\\BOARDCOVER\\BOARDCOVER.csproj": {}
},
"projects": {
"D:\\Algorithm\\2023\\BOARDCOVER\\BOARDCOVER.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\Algorithm\\2023\\BOARDCOVER\\BOARDCOVER.csproj",
"projectName": "BOARDCOVER",
"projectPath": "D:\\Algorithm\\2023\\BOARDCOVER\\BOARDCOVER.csproj",
"packagesPath": "C:\\Users\\USER\\.nuget\\packages\\",
"outputPath": "D:\\Algorithm\\2023\\BOARDCOVER\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\USER\\AppData\\Roaming\\NuGet\\NuGet.Config"
],
"originalTargetFrameworks": [
"net7.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net7.0": {
"targetAlias": "net7.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net7.0": {
"targetAlias": "net7.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json"
}
}
}
}
}
15 changes: 15 additions & 0 deletions 2023/BOARDCOVER/obj/BOARDCOVER.csproj.nuget.g.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\USER\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.6.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\USER\.nuget\packages\" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions 2023/BOARDCOVER/obj/BOARDCOVER.csproj.nuget.g.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v7.0", FrameworkDisplayName = ".NET 7.0")]
22 changes: 22 additions & 0 deletions 2023/BOARDCOVER/obj/Debug/net7.0/BOARDCOVER.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("BOARDCOVER")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("BOARDCOVER")]
[assembly: System.Reflection.AssemblyTitleAttribute("BOARDCOVER")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
083fce3fe7764a68a5c0219dfaea3c0a07959b30
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
is_global = true
build_property.TargetFramework = net7.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = BOARDCOVER
build_property.ProjectDir = D:\Algorithm\2023\BOARDCOVER\
Loading

0 comments on commit aa4cab3

Please sign in to comment.