Skip to content

Commit

Permalink
BOJ_1780 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
imyunha committed Feb 23, 2022
1 parent 4744dac commit 99732e7
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Algorithm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DC_1_Tromino", "DC_1_Tromino\DC_1_Tromino.vcxproj", "{A366ADF3-3435-4BF0-82D5-3A9393FB55DA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DC_2_종이의 개수", "DC_2_종이의 개수\DC_2_종이의 개수.vcxproj", "{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -21,6 +23,14 @@ Global
{A366ADF3-3435-4BF0-82D5-3A9393FB55DA}.Release|x64.Build.0 = Release|x64
{A366ADF3-3435-4BF0-82D5-3A9393FB55DA}.Release|x86.ActiveCfg = Release|Win32
{A366ADF3-3435-4BF0-82D5-3A9393FB55DA}.Release|x86.Build.0 = Release|Win32
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Debug|x64.ActiveCfg = Debug|x64
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Debug|x64.Build.0 = Debug|x64
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Debug|x86.ActiveCfg = Debug|Win32
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Debug|x86.Build.0 = Debug|Win32
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Release|x64.ActiveCfg = Release|x64
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Release|x64.Build.0 = Release|x64
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Release|x86.ActiveCfg = Release|Win32
{678EB73C-A420-47B1-AF1F-AB5CE7B682D6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 3 additions & 1 deletion DC_1_Tromino/DC_1_Tromino.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="main2.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="main2.c" />
</ItemGroup>
<ItemGroup>
<Text Include="input.txt" />
Expand Down
150 changes: 150 additions & 0 deletions DC_2_종이의 개수/DC_2_종이의 개수.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{678eb73c-a420-47b1-af1f-ab5ce7b682d6}</ProjectGuid>
<RootNamespace>DC2종이의개수</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="input.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
27 changes: 27 additions & 0 deletions DC_2_종이의 개수/DC_2_종이의 개수.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="헤더 파일">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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>
<Text Include="input.txt">
<Filter>리소스 파일</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>소스 파일</Filter>
</ClCompile>
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions DC_2_종이의 개수/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
9
0 0 0 1 1 1 -1 -1 -1
0 0 0 1 1 1 -1 -1 -1
0 0 0 1 1 1 -1 -1 -1
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
0 1 -1 0 1 -1 0 1 -1
0 -1 1 0 1 -1 0 1 -1
0 1 -1 1 0 -1 0 1 -1
97 changes: 97 additions & 0 deletions DC_2_종이의 개수/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// BOJ_1780

#define _CRT_SECURE_NO_WARNINGS

#define TRUE 1
#define FALSE 0

#include <stdio.h>
#include <stdlib.h>

void divideMat(int n, int start_row, int start_col);
void printRes();

// for convenience
int** mat;
int cnt_1 = 0, cnt_2 = 0, cnt_3 = 0; // counter of -1, 0, 1

int main() {
int n, temp;

/*
FILE* fp = fopen("input.txt", "r");
if (fp == NULL) {
printf("File open error!\n");
exit(1);
}
fscanf(fp, "%d", &n);
*/

scanf("%d", &n);

mat = (int**)malloc(sizeof(int*) * n);
for (int i = 0;i < n;i++) {
mat[i] = (int*)malloc(sizeof(int) * n);
}

for (int i = 0;i < n;i++) {
for (int j = 0;j < n;j++) {
//fscanf(fp, "%d", &temp);
scanf("%d", &temp);
mat[i][j] = temp;
}
}

divideMat(n, 0, 0);

printRes();

free(mat);

return 0;
}

void count(int flag) {
switch (flag) {
case -1:
cnt_1++;
break;
case 0:
cnt_2++;
break;
case 1:
cnt_3++;
break;
}
}

int check(int n, int s_row, int s_col) { // n by n matrix
int temp = mat[s_row][s_col];

for (int i = s_row;i < s_row + n;i++) {
for (int j = s_col;j < s_col + n;j++) {
if (temp != mat[i][j]) return FALSE;
}
}
count(temp); // all number is same!

return TRUE;
}

void divideMat(int n, int start_row, int start_col) {
int res = check(n, start_row, start_col);
if ( n > 1 && res == FALSE) { // exit condition!
for (int i = start_row;i < start_row + n;i += n / 3) { // divide to 9 matrices
for (int j = start_col;j < start_col + n;j += n / 3){
divideMat(n / 3, i, j);
}
}
}
}

void printRes() {
printf("%d\n", cnt_1);
printf("%d\n", cnt_2);
printf("%d\n", cnt_3);
}

0 comments on commit 99732e7

Please sign in to comment.