Skip to content

Commit

Permalink
https://www.acmicpc.net/problem/13549
Browse files Browse the repository at this point in the history
  • Loading branch information
1 authored and 1 committed Nov 13, 2016
1 parent 50b26d9 commit 27b0e63
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 9 deletions.
89 changes: 89 additions & 0 deletions BOJ13549/BOJ13549.cpp
@@ -0,0 +1,89 @@
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

#define MAX_N 100000

int N, K;

class Node {
public:
int position, cost;

Node(int p, int c)
{
position = p;
cost = c;
}

bool operator > (const Node &n2) const
{
return cost > n2.cost;
}
};



int main(int argc, char** argv)
{
int tc, T;
std::ios::sync_with_stdio(false);
#ifdef _WIN32
freopen("Text.txt", "r", stdin);
#endif

//cin >> T;
T = 1;
for (tc = 0; tc < T; tc++)
{
cin >> N >> K;

vector<bool> visited(MAX_N + 1, false);

priority_queue<Node, vector<Node >, greater<Node>> q;

Node n(N, 0);
q.push(n);

while (true)
{
Node node = q.top();

if (!visited[node.position])
{
visited[node.position] = true;

if (node.position == K)
{
cout << node.cost;
return 0;
}

if (node.position - 1 >= 0)
{
q.push(Node(node.position - 1, node.cost + 1));
}

if (node.position + 1 <= MAX_N)
{
q.push(Node(node.position + 1, node.cost + 1));
}

if (node.position * 2 <= MAX_N)
{
q.push(Node(node.position * 2, node.cost));
}
}

q.pop();
}
}

return 0;
}
153 changes: 153 additions & 0 deletions BOJ13549/BOJ13549.vcxproj
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>BOJ13549</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="BOJ13549.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="Text.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
25 changes: 25 additions & 0 deletions BOJ13549/BOJ13549.vcxproj.filters
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="소스 파일">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="헤더 파일">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="리소스 파일">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BOJ13549.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="Text.txt" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions BOJ13549/Text.txt
@@ -0,0 +1 @@
5 17
18 changes: 9 additions & 9 deletions BaekJoon.sln
Expand Up @@ -11,7 +11,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BOJ13260", "BOJ13260\BOJ132
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BOJ1533", "BOJ1533\BOJ1533.vcxproj", "{8B5D6C9E-C53F-485F-95A3-CEA19F835522}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BOJ12851", "BOJ12851\BOJ12851.vcxproj", "{D6C37D22-8332-49BF-84E3-237B94D142C8}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BOJ13549", "BOJ13549\BOJ13549.vcxproj", "{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -53,14 +53,14 @@ Global
{8B5D6C9E-C53F-485F-95A3-CEA19F835522}.Release|x64.Build.0 = Release|x64
{8B5D6C9E-C53F-485F-95A3-CEA19F835522}.Release|x86.ActiveCfg = Release|Win32
{8B5D6C9E-C53F-485F-95A3-CEA19F835522}.Release|x86.Build.0 = Release|Win32
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Debug|x64.ActiveCfg = Debug|x64
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Debug|x64.Build.0 = Debug|x64
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Debug|x86.ActiveCfg = Debug|Win32
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Debug|x86.Build.0 = Debug|Win32
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Release|x64.ActiveCfg = Release|x64
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Release|x64.Build.0 = Release|x64
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Release|x86.ActiveCfg = Release|Win32
{D6C37D22-8332-49BF-84E3-237B94D142C8}.Release|x86.Build.0 = Release|Win32
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Debug|x64.ActiveCfg = Debug|x64
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Debug|x64.Build.0 = Debug|x64
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Debug|x86.ActiveCfg = Debug|Win32
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Debug|x86.Build.0 = Debug|Win32
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Release|x64.ActiveCfg = Release|x64
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Release|x64.Build.0 = Release|x64
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Release|x86.ActiveCfg = Release|Win32
{9ECBF88B-E657-42FC-B6A5-3F6CE58A41F7}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 27b0e63

Please sign in to comment.