-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from fkdl0048/18-algospot-시계-맞추기
Sovle: CLOCKSYNC
- Loading branch information
Showing
29 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") = "CLOCKSYNC", "CLOCKSYNC.csproj", "{0270D226-274B-4215-A95A-6CB80FE4E845}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0270D226-274B-4215-A95A-6CB80FE4E845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0270D226-274B-4215-A95A-6CB80FE4E845}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0270D226-274B-4215-A95A-6CB80FE4E845}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0270D226-274B-4215-A95A-6CB80FE4E845}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {70E32DE1-3D84-498A-BF36-5A5E2EBDBCAC} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
namespace CLOCKSYNC | ||
{ | ||
public class ClockSync | ||
{ | ||
private const int SwitchNumber = 10; | ||
private const int ClockNumber = 16; | ||
private const int Inf = 9999; | ||
|
||
private readonly string[] Linkend = new string[SwitchNumber] | ||
{ | ||
"xxx.............", | ||
"...x...x.x.x....", | ||
"....x.....x...xx", | ||
"x...xxxx........", | ||
"......xxx.x.x...", | ||
"x.x...........xx", | ||
"...x..........xx", | ||
"....xx.x......xx", | ||
".xxxxx..........", | ||
"...xxx...x...x.." | ||
}; | ||
|
||
private readonly int[] _clocks; | ||
|
||
public ClockSync(int[] clocks) | ||
{ | ||
_clocks = clocks; | ||
} | ||
|
||
public int Solve() | ||
{ | ||
var ret = Solve(0); | ||
|
||
return ret >= Inf ? -1 : ret; | ||
} | ||
|
||
private bool AreAligned() | ||
{ | ||
for (int i = 0; i < ClockNumber; i++) | ||
{ | ||
if (_clocks[i] != 12) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private void Push(int switchNumber) | ||
{ | ||
for (int clockNumber = 0; clockNumber < ClockNumber; clockNumber++) | ||
{ | ||
if (Linkend[switchNumber][clockNumber] == 'x') | ||
{ | ||
_clocks[clockNumber] += 3; | ||
|
||
if (_clocks[clockNumber] == 15) | ||
{ | ||
_clocks[clockNumber] = 3; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private int Solve(int switchNumber) | ||
{ | ||
if (switchNumber == SwitchNumber) | ||
{ | ||
return AreAligned() ? 0 : Inf; | ||
} | ||
|
||
int ret = Inf; | ||
|
||
for (int count = 0; count < 4; count++) | ||
{ | ||
ret = Math.Min(ret, count + Solve(switchNumber + 1)); | ||
|
||
Push(switchNumber); | ||
} | ||
|
||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace CLOCKSYNC | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var testCaseNumber = int.Parse(Console.ReadLine()!); | ||
|
||
for (int i = 0; i < testCaseNumber; i++) | ||
{ | ||
var input = Console.ReadLine()!; | ||
|
||
var clocks = input.Split(' ').Select(int.Parse).ToArray(); | ||
|
||
var clockSync = new ClockSync(clocks); | ||
|
||
Console.WriteLine(clockSync.Solve()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
"CLOCKSYNC/1.0.0": { | ||
"runtime": { | ||
"CLOCKSYNC.dll": {} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"CLOCKSYNC/1.0.0": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"format": 1, | ||
"restore": { | ||
"D:\\Algorithm\\2023\\CLOCKSYNC\\CLOCKSYNC.csproj": {} | ||
}, | ||
"projects": { | ||
"D:\\Algorithm\\2023\\CLOCKSYNC\\CLOCKSYNC.csproj": { | ||
"version": "1.0.0", | ||
"restore": { | ||
"projectUniqueName": "D:\\Algorithm\\2023\\CLOCKSYNC\\CLOCKSYNC.csproj", | ||
"projectName": "CLOCKSYNC", | ||
"projectPath": "D:\\Algorithm\\2023\\CLOCKSYNC\\CLOCKSYNC.csproj", | ||
"packagesPath": "C:\\Users\\USER\\.nuget\\packages\\", | ||
"outputPath": "D:\\Algorithm\\2023\\CLOCKSYNC\\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" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
4 changes: 4 additions & 0 deletions
4
2023/CLOCKSYNC/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("CLOCKSYNC")] | ||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] | ||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] | ||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] | ||
[assembly: System.Reflection.AssemblyProductAttribute("CLOCKSYNC")] | ||
[assembly: System.Reflection.AssemblyTitleAttribute("CLOCKSYNC")] | ||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] | ||
|
||
// Generated by the MSBuild WriteCodeFragment class. | ||
|
1 change: 1 addition & 0 deletions
1
2023/CLOCKSYNC/obj/Debug/net7.0/CLOCKSYNC.AssemblyInfoInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
400f4a149c25c287f61318a5a2bfde42f20f90ab |
11 changes: 11 additions & 0 deletions
11
2023/CLOCKSYNC/obj/Debug/net7.0/CLOCKSYNC.GeneratedMSBuildEditorConfig.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = CLOCKSYNC | ||
build_property.ProjectDir = D:\Algorithm\2023\CLOCKSYNC\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// <auto-generated/> | ||
global using global::System; | ||
global using global::System.Collections.Generic; | ||
global using global::System.IO; | ||
global using global::System.Linq; | ||
global using global::System.Net.Http; | ||
global using global::System.Threading; | ||
global using global::System.Threading.Tasks; |
Binary file not shown.
Binary file added
BIN
+73.5 KB
2023/CLOCKSYNC/obj/Debug/net7.0/CLOCKSYNC.csproj.AssemblyReference.cache
Binary file not shown.
1 change: 1 addition & 0 deletions
1
2023/CLOCKSYNC/obj/Debug/net7.0/CLOCKSYNC.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
28481db4a50264cc9716e7cde768be471088fec8 |
15 changes: 15 additions & 0 deletions
15
2023/CLOCKSYNC/obj/Debug/net7.0/CLOCKSYNC.csproj.FileListAbsolute.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
D:\Algorithm\2023\CLOCKSYNC\bin\Debug\net7.0\CLOCKSYNC.exe | ||
D:\Algorithm\2023\CLOCKSYNC\bin\Debug\net7.0\CLOCKSYNC.deps.json | ||
D:\Algorithm\2023\CLOCKSYNC\bin\Debug\net7.0\CLOCKSYNC.runtimeconfig.json | ||
D:\Algorithm\2023\CLOCKSYNC\bin\Debug\net7.0\CLOCKSYNC.dll | ||
D:\Algorithm\2023\CLOCKSYNC\bin\Debug\net7.0\CLOCKSYNC.pdb | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.csproj.AssemblyReference.cache | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.GeneratedMSBuildEditorConfig.editorconfig | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.AssemblyInfoInputs.cache | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.AssemblyInfo.cs | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.csproj.CoreCompileInputs.cache | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.dll | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\refint\CLOCKSYNC.dll | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.pdb | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\CLOCKSYNC.genruntimeconfig.cache | ||
D:\Algorithm\2023\CLOCKSYNC\obj\Debug\net7.0\ref\CLOCKSYNC.dll |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
2023/CLOCKSYNC/obj/Debug/net7.0/CLOCKSYNC.genruntimeconfig.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e76ec4bf4ce9fb70ed9aba0c46506dc602c0d448 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.