From 2f8060e6db573d9230ee6c0be828fa5c37e23566 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 30 Jan 2023 21:50:32 +0900 Subject: [PATCH 01/30] first commit --- .classpath | 10 +++ .project | 17 ++++ .settings/org.eclipse.jdt.core.prefs | 14 ++++ .../BOJ_10972.class" | Bin 0 -> 2033 bytes .../BOJ_11051.class" | Bin 0 -> 1423 bytes .../BOJ_1269.class" | Bin 0 -> 1734 bytes .../BOJ_9375.class" | Bin 0 -> 2457 bytes .../BOJ_1120.class" | Bin 0 -> 1398 bytes .../BOJ_18111.class" | Bin 0 -> 2267 bytes .../BOJ_2503.class" | Bin 0 -> 2008 bytes .../BOJ_2615.class" | Bin 0 -> 2330 bytes .../BOJ_10972.java" | 69 ++++++++++++++++ .../BOJ_11051.java" | 35 ++++++++ .../BOJ_1269.java" | 46 +++++++++++ .../BOJ_9375.java" | 50 ++++++++++++ .../BOJ_1120.java" | 36 +++++++++ .../BOJ_18111.java" | 66 +++++++++++++++ .../BOJ_2503.java" | 76 ++++++++++++++++++ .../BOJ_2615.java" | 75 +++++++++++++++++ 19 files changed, 494 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.class" create mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.class" create mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.class" create mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.class" create mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.class" create mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.class" create mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.class" create mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.class" create mode 100644 "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" create mode 100644 "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" create mode 100644 "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" create mode 100644 "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" create mode 100644 "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" create mode 100644 "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" create mode 100644 "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" create mode 100644 "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..5cd108a --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + 알고리즘 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git "a/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.class" "b/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.class" new file mode 100644 index 0000000000000000000000000000000000000000..670948612e4c236101c5cc286655995c6cd3e45a GIT binary patch literal 2033 zcmaJ>Piz!r6#sp@GdtbsK%r$?`o~g0Wee>tZDA1#BITb8rHd4*6}3*g(=zRLb~Bwt z)Wm~wAmQY}m>4`1W2!f)rfsP9WMab2n+Fdj9!N}$iAO?Qf8T7|Eungt`QG>5`@Z*k zzxTfP;Gg?T0FEKAAtcbeeCy8gr{4`NPk;00CtnXO&wR`!(UU$m)Up5Yp-v5oz?O0A zx|PUU?pPu{JZ_Kp0%6PZ1VUF+0+FMR>-aBH7i%35P)_DDwvI3=4QQwksOoiGyRR@g zYwkC3w&t=KD2L0}nK27zs{)~8w1(T2E&c7d&Bu2QaV zkJ+Aq1orcayyZ>V)DiSbw4fnYc~3=LG7?q?B^$DL7g7fR0}DX}IuYk%LAw zkj6!Zxo%|(c6wB1n%a=~6p|I_7Z5EvQn+GZ0I%{*S^2!}W(3+d;`*rquHa$nDGVBT zJ*c^#D}j}KykX!?$+sG$%^WRnjE}8mgBQfk9Ol#BzQ*m7eb4tN`uOqTho)GA#**Jg zg_f=kYvp8aP#WiF32f^3t&xcfRz7(48iq7Ph==cjoa_C$f;VEHapaWPyf%d5l7H-E zjl!H<>_ypSl){ubV)&18m*6V6s(a_5-=h$M!G9!BZp9|bM#%x2QN>*pTdtcG29GeFB2i#CB>aJj#ZJ$N56e8`dX5l`GkJMJKk zFIl*+xS!>tzmEg>0SECTlK2US@PPZD(T#^VDg?SkB_qf>j+W|!w=l$AH6Gz@SgdUW z{>CsySkpHAh74?CPH=3DQl}8r5)nzMAG-scid)!=Yt*TXeQ8B{$a@^>A{giGXHivT za;k<24Ru087n`i=F=|9z=n)j-F*MOcDe@S)FpBIUeVr>?l1H*&z^EKA1SxyfA_&>b zb*xB3{FwanYmBGmzbRer-fB7mCy1qo-FlLop9&agDIE{8pabh5v*6%hM^91;QFf^h GA@?s2-_jBQ literal 0 HcmV?d00001 diff --git "a/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.class" "b/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.class" new file mode 100644 index 0000000000000000000000000000000000000000..d40e494f58efa04c3ab8e8660fb157842da6515d GIT binary patch literal 1423 zcmaJ=&u<%55dOyA-50ytG;z8~nl!~NnAmNx>p%@OZGe=tb?d~XP9sG*q#OIyZ0fA7 z^%|94=>fzEA%rUR08*t0dVzov)JWX8@VA7203pJ>wG+2$gtTwp%$wie%>4Q9v)=(+ z!fk;N;l$48k9WTPb$RFepZ@yhhvl91ulUML7q2g8v**rd1vEn6s{M(bso8EdQ(Re< zWuIU)>}J`n5yDGLd1fy)tB#>4SGlcO@#GvOLSYI|& zStgJ*F`>dlTzTIQ5{Tk0-A6^o=!N=jVN;q8d?ee`@yAe#jz*QdE zQoZGsUL0XAf{cV4#xt3T~Ay^7=C71c6PUiez09yK%gyc1xmZN7HkVeOFtKvQdy+Zs(5yHfJ2wFo3m$0 zF<#ch8!v29Z4+ZcydavGXk(y}#vkCNH~s^!@DG?qeCF&2i=r22X3qOQ@AotF%U?hJ z4B#SWBzyvG8=ri+@x_nR8_VDS@#vfBjg`;1#fHa5rca;gKQG}I*gJ17nz5{D&&I}5 z^D6BM1O_eJa)$)!y1FL?{FieX6-FIG2I>(I*pskqb+fpTQqF{#$|`}zL@sS+Cr!uF z|7D@yowEu89f|)bjfQN+#(#mOVS569`|upH_L-%Gm{pMuCWjvU0Kb zSXCpjpB^fT;o{7Ua#UtqnHl9sGzm0Uba6Xhbm?803ng_32hk$Yysa0>rGl##47B1U z0iRAUT1rlb-SRLHMilM3FC790yLNGCzBV=HKefIbs4vwwCle&7Tl)iC>)GFtaQu;v+Tqa-%iQ;%5>w zXXbfIvBlf3=2E_LJn3GfvHd_3{V;41kS<1V<@_pBlKgQpI2)oP#tySN%90QUy|g|HiY=wvU? zeron(jw?tyzvAf+N@xA zRYWIJL}k>!y!q=>TyCyk#r0?)vx+x$^?vB;C;5PYRW`E9cCN>H*<+NQ!vS0&l}FHw zBwFx3&$DR5JW-42z(+WQk8uPKd7U5OC?3=DYs$Yv57yD^bu;g+&+!(<8KV*3($fU{ z*p9F8HY59J^Eqzg9gZu8Pcg-lpOGKn4(_tc*BRqo$^x|8h4*-pj6cp?v}_4yJ*{LO z?U<%4hz}S?&#>gfq>mIO#}L?LAyOhO5s~N=LZXjTZ+d|i@dB;lPlPpBG6ege{s#Oa BncDyW literal 0 HcmV?d00001 diff --git "a/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.class" "b/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.class" new file mode 100644 index 0000000000000000000000000000000000000000..2bf6081b230df813b756f23fe9ae8c5173bab945 GIT binary patch literal 2457 zcmaJ@O>k3H6#j0S^d{j|pb*+n{-w}DAp$l)0u@_9f-MDFTM9~fOhB?UAd6@-It_E_*>-N_wG6OJLi1o=jP`- z-+d2YFD^+q1Xj*oygd8)xBatMzxnI4ulr{wE^!I8b{^{Ay<=yygi~PA8GTF-#P!5b zpmX4i5w!#=_m~OOY7wYtXzUSiwk2bR7ZvbmaG_FQVY`_y4rfOPjC8j?5H|#>+mlf} z-lL~Y^_|~zTEk{WV0HULoe0ywsBR_%mNlGgFFMm@rOm`pSUKR`e=cgIEHjzNNK_NC zsFm~LKr%h5Tk~2HO9htLN@g+;=`0Z}qnU!BH9I(Hq>b1yLysA0iCO`FK^94*vKC!1 z^wFHygXLHuQCCJ-*LcPGm!=p-R zJ)JKq<;;@@i46iZ#n5vEwPwvYz4xLX9)-}TVG}kBxaoRK!12#E!!8tYyXn2ldQwho16cJ3JD>0-d%j zcc?o#VkFG-%HL+}Qo-(i066JrMp(lh6^tigoU`n+3($gn5>E(J*>2m|w5j1qw6b7_ z40^kv)Z1K9hf68QZz&3%(y$)~1mu_=&l;VBstO~ex_L^%%J4xA5geiw)`q~Y`&cRA z`QdikHFV%GIW`kkk1}mHTSQqoqTwixu?uaN*g&;~{Mo^_CF5~+DVu>lb%SN`EK^)0 zqbS$Vi{r|KWu$d0nO3poL$i@0`F-M?z;hBO*~dkkf>guvIK>`SDY(0q@-eFOr#0vp zAd$m*=CG~G;c-HhWlVzs5?iUKQbr;su%evdvN{gCF)Sdw>fjl5a718BDba=ED`C1E zKs72`GJzy1O{zo{d-4cJO1`VvlP`edgsjX@iW0E~3t0hIN}af?L<^Z!qft)}F+)r4 zGq^Yq1_)j|-|gk&hGWl>Az%In20|LT`HN7|iZYf_J*7r(F+(hSq6k)zFclj8tSb@U z)p1m<7%|4xthOOaTbap88<}jJ2x5$7Qa;VcQ-z5hEPJ@+D&>=Zhug_f(jEIm5H zBlguGaaQ7^@=0n>dye|9WHuc&4w&jzsVZDlTb0LH3x>eU4RG*{HxZwbUjeRyt83E~ z+}CWemro@ImSO>)T26s$6~8=q1PckW$kuXTF_tJG$5Dc+lmE=X*EfTjzU%N$Vf7T& zwa=iwZwebbHcz7A2AW!&LFWW+&0srs9}l_m+ri3;pq#+*88r8)ttspbx&7`*gnI2~ z$m4hUJ=56hz>iq0-YagPZ5mHkpjUm(OK)MzB%X1eo|j&b!Y6%|SLY_2LFso*qf=lS zT>>G`1nLxKpFr+Z&`nLZ^Ykzkx!*7F#oX;CpLE715$$cN9-4&Nd%-Du&Xr%z?YoY6 z(0{eK|bzl{`u$pbZ7K7BVupXaMb{QLS z1&z4LJLo5_zjDI_w(#9e%+} zc$xXG#}9agZ%&@QhF9?#lN7>Nc%6Hd{G-#4H~1#$(|){(3vkn`U3d#`GtF1fhIee~ zO@3YEn;Y-aqAG_R+IvKMpF2H}a}3iZ@qvU-qF%6g?x04ZMTq~fLxTU7KKvJJ=IEri YM9Ws7`4d3R94RPApq-D2?!YJi16Y7*=Kufz literal 0 HcmV?d00001 diff --git "a/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.class" "b/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.class" new file mode 100644 index 0000000000000000000000000000000000000000..e9f557abccecbc1c4263477b547d2658407d950c GIT binary patch literal 1398 zcmZuxU2hvj6g}gwS(^gIoTSugq=-tev8Tx<_S#yn zQ9(#N)I9J2;*}=~s?_K9!I6m6AHW~rPlP{E3CtNgAB`Hxo|!x6&b@ceJ+puP_vdo} z*Rd=S5U_TBZSOp4|MT#dorgbW^NY8>oSeKgArTT7+OWU2vsK$&%Py{NsIo5*x#qZz ze?uUc&MXUrX6h9cLl99DVMGK5i;k-nTD4W>E!nG8B@i#x%XW3y_8e{RZif7IrztQ} zJTmzd1J`WF6*!juqIgh5$@d(0ZAvGO%|0lrhVRtfrbJvI(erZZ*}~#JA~DPedqBQ* z|Gx56<&Lr|%9A)Ikle!xZlmQhy0UA1IEv#qA(1@9LFt>OuWBYnaZ(_l%d`5$>9hwC zred%#ruleF;CT8-m&|eu37pnWXIT7!Q$IbgDDn1Qfi2&uX8U(vs&6XS`Br)Q_*oP0 zA}wIB?uzDJU^tz5m9H35IHyycXT`gzdQIKuQ+te?xTvE=UG>246W4H^cD+Ua1NLsS zue0VI@#(fhMaN z?c+z0O&2k(mHdhn3FLX5nihj7@bA!a>kKD01O`gJUEZ9x8$H!a%u=_dddn-TIY&Q@ zfxXvuQ3u9p@GxH{5a5c>iKC>IpH4MCt*EpJe2hIbuqTC&1kRh%^ zMBdP0M3W(--1&JMiIr_wE6*^pg*Ufws<@5R%J~l7*+ORiLI)QX^l&v4&*s9xT;vJn zf;kz?8BcI_+%h_tNQSJ4WqifeZ-}&|u%s1!3_1?B4PhDM9prxR{;hZafV5;T+>Qt< zk_>TQW0l9KVl%PT~$d z?$KVyDKv@yfHU}sCo~uL`nSYQ%+iYEJIvt|vM`1QK1G4Nq_Bxw_>6foP$+U0Vip_o zSRh9exXT<1pnNJyk4CixTW$GIZYZ91MZMEY26988A?+OX(;WF{geE}6CO$j zhD9t8m5{n%0|==RL)hY=q#_b4xMKju^(S8QMYE*{j6IFDs1X##hi9q@7m(tT_%DQD{<@GKN0X#3@Vcc<IFtzfwBou&8M_@Nkd3_t4o9ZYoJDRUmcT{zxPuvnX&u!z=R0l}QwGvT(y1F5y*jG+mH!RSR%|?5R|_N5yLb zn^&JzPDQw2B}fi0Mlh=4^3&C~$*18BToF*O8;OEBG%lYVshRR9f*xFB6YcOKiZKl_ z#2L1c$(Sh$2Wr*fnbK9_A)}%gmo6p*T518VHMBHL*|f-~%dhexfs~5mnl4$B3JqyV z3?(D8!z>!v3Fdc0jlLu4$Fj0(SK8+3mSWdBa`ez#KCi`Enh1;ElpH#;fy5*~&Xx7U zc_TJGU}P!-!aJNUWMk$TOOBBG>ICbO$k@rEJ2~#$@JQZJ@<@W&E9qsgB$vICNcKt^ zadq(~=M?`9+y%G_uFC#JG=4|HfhPXlw$g(Ql(n(}HbUpF4x6xO>ac~~Ts#0H7I#I&068awCq+=eZ zoV{}huD$CFx#pmkaH=(^yDFE4iY}qMcxiU|&!SVb(!=cXFHL89Y3vLsbGYrC$Jr82 z%p>9qx#w`+8B*tPgkE%aP*=NjdJkbpM$m{4;59Rt2We6MYqu1 zHr6~L&(6YELgaI-qui@2Ay-imy5bXJc6p|Ri%W=(wBE<-i+Ho?>H-YiwE%MglM9%Z z33u8F|9}+*e3YB8ovHRS*+HiIC=(sQHVkssT}BJ8ajvGh-lDF^KL3#S?w}2KIgvlX zZhVG4xQD&?2K(?my)2>~53nDt;izBQg0VNpsSeZKvQ1 z4BK{Ye2Fllmu$UF@13ZBf?Q1=Ke4w8>kj*&>_ zTBMxpfL+Xe3+uNn*xVJ5v(T)9tE!m1Mgpwzy57EW1dSZsZA`A@_l~j~J3MZgNEx1N rid}Z_5|(qf3hS!ER#02w1d*^xRZ$bRkFduHd*Xk>3cSN09C-I%i#zD8 literal 0 HcmV?d00001 diff --git "a/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.class" "b/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.class" new file mode 100644 index 0000000000000000000000000000000000000000..1c6b809793effe4a1b66bd93aba05a5da03183d0 GIT binary patch literal 2008 zcmZuxO>7iZ9RIz}?9R?~w!4%L6tKvLK+8uLD4mLwf_&-XLXnnAL4oOZ+D^OOU1oO) z9~Z@5OiVQKgqPOD*ozmdQeugT7d2iy=t&PIMo(hAc+n8+@6B{u(C%j5`@R3y`+vS~ z{`u^400%Lkp+>-ZaA)Gd)Wq+vzy09#H&REsPhQ^JzPn9>Dv%s?t~sfklOIlX4~)9m zvVh|FzCg{zv_P~}_PsGzKpk*$Ii5ScyjSj`Omj;gsYeTgt^oyc6FLlmM8?azrz_(F zuHWknL`ve6dodb=MgW z**c!UdJRpFrKjgcsqBuMcoG|!9qFDGIw!APvT(q_8f=pJ*euZ4ysSt|pMllbB89fn z`6Z$7dWI1}0rSoNX*!4}Mu$v}|j$d*~ zqtgqw1tqVhG_6BmuZakv674ggg~&D$LsY}l)pS+LUM>}?^%ln5ym!;}4Rqic84N48 zta*mhfrBQxWH@@>yih`X#B+FF zKr2d(9Lu6Mr-SBn{9!iP%4J%J^&4P|H!j}xcy}<2ni9QP7xI@2nIhseKhB8oI2XQK zs^qAm4&|I-(k}2D;YX6F@EfH}cErt&(bEw0R>3)HWf^O@F%|KivXdP<jaF%+b^(TV%<8FV#}&Iyu@f{^JB8>(ouD;y0qItJ0cn;w34=lbAt8lo zB_Xy*&_jYADksDY+Ih8=m_nV5ny_vXI%AqfLban4hOi9Ad&P?0;kBxmhzKjPLizFi zd1D5LEcGsq%GxQAwfle%1&HcdueDq^uwGkPubo(hy?jZ!(1;iKES)FUB`wdvyNV`U z$9mji1Kq|Zyot?thgvh(hEK5_bJ&3|Y2kb9!cS<$&upAuY3&cR;VmBPV!VQMo7=FtN1qH z6i&0x)`~0W#u>(z!Xdm!q~fa3aW+5|JPc?Ndj1=F(96!fjbCt%T#ZrufIgxaWBCp* z5$U+c{G2B;7|&biC#q#sui*lb$=I&pB2k4m{~Cy9xPcP5G#c%cdE>ihL)KcOx=-+9mb|32^g zz5RCStA_yk@IHr)K|H-S^K^FR_p2X2z50=VAbjjxS71*!hr&=fpd8w^#UL{yIt=_ylw z7nw@>ygAKK8!8*TmmE*&rp2(nc{sF^#9%sQTI0PkuzKWD)JUeygf-1k#ZaBsG86t_ zcv-?xLmocyD(?k)o>HT)WO zOK)z=xRlPvQPG9H94|4fTWLnnN*m)wN<%jS6gsJ=rVZl#kLRF7^kohE(L-e=GE#3D znUmDkBK!p20ldP|x2mP9#2OCb5Ccz2i#T;aX%0%P256R6QY(}*kTK)bX%(;HD94et zt;|o7hS%^qdAp#;Ge&q!rXDN{TR+-ec!Pm$Rnd>*8crZgcR^1k4J*dbQ4Y%&;4kJw z753vz>EaZ_rg8ySE1uSHCg0k0qEMB@=Pd~X^-$4M<8+Iv%iIwf(9sl)-!jH)$DeMP zZJK&eUyzp@EK;%SDe_^9U7}++D5=YYfk_X2unBr5NhvCuZnLD4MRFyXGA0eP71n+owEBD)slL@D!zL%EFl-ev((C$=j!dE06v+R&P;F@Q9m4I6~ z>lESY90{m`*E#Z(r>Gaugj!iW$5f$SXAa>Z8cV`+1O4;(bH>etx@_txnF_b-HYn}Z zyeS&V6b%K_T4_q6iVmT62~VfcZsr~o!^Z;NV)$6VC%o6uB)l?QgYaEPo$yJzszZ3Y zgpcfIrJFQ`nuT=_`-GN7ui&DPMC>-YiMfdWNHM{fGIAe>7Z9vEmPM$fri^59GK;}1 zhUT%eWZ_(^%U5aLopCYY;zeL(a?>Xrog_70pRKO-VaV zL?6w^Vd8{orJg|zqV%33-bGqnAD|9bN%I;u<0cv~hb_2+t;o`_KEif9K_h;|PW*&j z_yx^)MjQDrwBkA1SQXltKoi@B-K-6JSU0*@gtqBf>|>+Y&n9qyU8IfoIS#VN=x5(y zGy8#ldw#|S_A4!@XE>Ih?K_kUO)cI=gmSMU`8ybf|df1QVoW GL-Id6{Qdp_ literal 0 HcmV?d00001 diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" new file mode 100644 index 0000000..7e3a69b --- /dev/null +++ "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" @@ -0,0 +1,69 @@ +package 순열_조합_집합; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** + * + * 다음 순열 : + * 1. arr[i-1] < arr[i] && i > 0 을 만족하는 i 중 가장 큰 i + * 2. arr[i-1]을 기준으로 두 덩이로 나눠, arr[i-1]보다 큰 수를 찾아 arr[i-1]과 swap + * if(arr[i-1] <= arr[j]) swap(i-1, j) + * 3. i부터 j까지의 구간을 오름차순 정렬 + */ +public class BOJ_10972 { + static int[] arr; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + arr = new int[N]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < arr.length; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + int idx = 0; + for (int i = N-1; i > 0; i--) { + if(arr[i-1] < arr[i]) { + idx = i; + break; + } + } + + // 내림차순으로 정렬된 상태, -1 출력 + if(idx == 0) { + System.out.println(-1); + return; + } + + for (int j = N-1; j >= idx; j--) { + if(arr[idx-1] <= arr[j]) { + swap(idx-1, j); + break; + } + } + + int j = arr.length-1; + while(idx < j) { + swap(idx, j); + idx++; + j--; + } +// Arrays.sort(arr, idx, N); + + for (int a : arr) { + System.out.print(a + " "); + } + + } + public static void swap(int i, int j) { + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } +} diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" new file mode 100644 index 0000000..c3b487e --- /dev/null +++ "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" @@ -0,0 +1,35 @@ +package 순열_조합_집합; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * + * 이항계수2 : 이항계수 : ( n k ) = (n! / (k! * (n-k)!)) == 파스칼의 정리 + * + */ +public class BOJ_11051 { + static int[][] pascal; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + int N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + pascal = new int[N + 1][N + 1]; + + for (int i = 0; i <= N; i++) { + for (int j = 0; j <= i ; j++) { + if( j == 0 || i == j) pascal[i][j] = 1; + else pascal[i][j] = (pascal[i-1][j-1] + pascal[i-1][j]) % 10007; + } + } + System.out.println(pascal[N][K]); + + } +} diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" new file mode 100644 index 0000000..16e799e --- /dev/null +++ "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" @@ -0,0 +1,46 @@ +package 순열_조합_집합; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashSet; +import java.util.StringTokenizer; +/** + * + * 차집합 : HashSet으로 중복제거 + * A + B - 2 * A∩B + */ +public class BOJ_1269 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int A = Integer.parseInt(st.nextToken()); + int B = Integer.parseInt(st.nextToken()); + + HashSet set = new HashSet(); + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < A; i++) { + int a = Integer.parseInt(st.nextToken()); + set.add(a); + } + + int hap = 0; // 합집합의 개수 + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < B; i++) { + int b = Integer.parseInt(st.nextToken()); + + if(set.contains(b)) { + hap++; // A∩B + } + else { + set.add(b); // A + B + } + } +// System.out.println(A + B - 2 * hap); + System.out.println(set.size() - hap); + + } +} + diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" new file mode 100644 index 0000000..d552a17 --- /dev/null +++ "b/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" @@ -0,0 +1,50 @@ +package 순열_조합_집합; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; +/** + * + * 패션왕 신해빈 : HashMap을 이용한 조합 + * 모자가 4개 안경이 2개일 경우, + * 하나만 쓸 경우를 포함하여 [headgear] = {1, 2, 3, 4, NULL}, [eyewear] = {1, 2, NULL} + * 둘 다 NULL인 경우, 아무것도 안 입을 경우의 수 1개를 빼준다. + * 5C1 * 3C1 -1 = 14 + * + */ + +public class BOJ_9375 { + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + int T = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= T; tc++) { + Map map = new HashMap(); + int N = Integer.parseInt(br.readLine()); + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + st.nextToken(); // 버림 + String key = st.nextToken(); // 키 + // 처음 들어온 key라면 0으로 reset + if(map.get(key) == null) { + map.put(key, 0); + } + map.put(key, map.get(key)+1); + } + + int result = 1; + // value 개수에 안 입을 경우 NULL 추가 == v + 1 + for (int v : map.values()) { + result *= v+1; + } + // 아무것도 안 입었을 경우 -1 + sb.append(result-1); + sb.append("\n"); + } // end of TestCase + System.out.print(sb); + } // end of main +} // end of class diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" new file mode 100644 index 0000000..1050108 --- /dev/null +++ "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" @@ -0,0 +1,36 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * + * 문자열 : + * + */ +public class BOJ_1120 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + String A = st.nextToken(); + String B = st.nextToken(); + + + int min = Integer.MAX_VALUE; + for (int i = 0; i <= B.length()-A.length(); i++) { + int not = 0; + for (int j = 0; j < A.length(); j++) { + if(A.charAt(j) != B.charAt(i+j)) { + not++; + } + if(not > min) break; + } + if(not < min) min = not; + } + System.out.println(min); + } +} \ No newline at end of file diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" new file mode 100644 index 0000000..b1b5afb --- /dev/null +++ "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" @@ -0,0 +1,66 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BOJ_18111 { + static int[][] map; + static int N; + static int M; + static int B; + static int time; + static int Block; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + B = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + int min = Integer.MAX_VALUE; + int h = 0; + for (int i = 0; i < 257; i++) { + time = 0; + Block = B; + for (int j = 0; j < N; j++) { + for (int k = 0; k < M; k++) { + if (map[j][k] == i) + continue; + else if (map[j][k] > i) { + minus(j, k, i); + } else { + plus(j, k, i); + } + } + } + + if (min >= time && Block >= 0) { + min = time; + h = i; + } + } + System.out.print(min + " " + h); + } + + public static void plus(int j, int k, int i) { + Block -= i - map[j][k]; + time += 1 * (i - map[j][k]); + } + + public static void minus(int j, int k, int i) { + Block += map[j][k] - i; + time += 2 * (map[j][k] - i); + } +} diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" new file mode 100644 index 0000000..bbb74f3 --- /dev/null +++ "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" @@ -0,0 +1,76 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BOJ_2503 { + static int[] arr; + static int[] strike; + static int[] ball; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + arr = new int [N]; + strike = new int [N]; + ball = new int [N]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + arr[i] = Integer.parseInt(st.nextToken()); + strike[i] = Integer.parseInt(st.nextToken()); + ball[i] = Integer.parseInt(st.nextToken()); + } + int result = 0; + for (int i = 123; i <= 987; i++) { + boolean flag = false; + + + int h = i/100; + int t = i/10%10; + int u = i%10; + + // 같은 수가 나올 경우 || 0이 나올 경우 continue + if(h == t || h == u || t == u || t == 0 || u == 0) { + continue; + } + + for (int j = 0; j < N; j++) { + int checkH = arr[j]/100; + int checkT = arr[j]/10%10; + int checkU = arr[j]%10; + int cntS = 0; + int cntB = 0; + + // strike + if(h == checkH) cntS++; + if(t == checkT) cntS++; + if(u == checkU) cntS++; + + // ball + if(h == checkT || h == checkU) cntB++; + if(t == checkH || t == checkU) cntB++; + if(u == checkH || u == checkT) cntB++; + + // ball과 strike 횟수가 같으면 true 아니면 false + if(ball[j] != cntB || strike[j] != cntS) { + flag = false; + break; + }else { + flag = true; + } + } + // N번 다 true일 경우 가능성있는 답 개수++ + if(flag) { + + result++; + } + } + + System.out.println(result); + } +} diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" new file mode 100644 index 0000000..b5bea6f --- /dev/null +++ "b/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" @@ -0,0 +1,75 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BOJ_2615 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int[][] arr = new int[19][19]; + int[] dx = { 1, 0, 1, 1 }; // 오른쪽, 아래, 좌측 대각선, 우측 대각선 + int[] dy = { 0, 1, -1, 1 }; + + for (int i = 0; i < arr.length; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < arr.length; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr.length; j++) { + // 1또는 2일때 연속되는 지 검사 + if (arr[i][j] == 1 || arr[i][j] == 2) { + // 가로 세로 대각선 검사 + for (int k = 0; k < 4; k++) { + int cnt = 1; + int nx = i + dx[k]; + int ny = j + dy[k]; + int prev = arr[i][j]; + if (nx >= 19 || nx < 0 || ny >= 19 || ny < 0) + continue; + // 5칸 검사 + while (arr[nx][ny] == prev) { + cnt++; + nx += dx[k]; + ny += dy[k]; + if (cnt > 5) + break; + if (nx >= 19 || nx < 0 || ny >= 19 || ny < 0) + break; + } + + // 6개이면 break + int px = i - dx[k]; + int py = j - dy[k]; + if (px >= 0 && px < 19 && py >= 0 && py < 19 && arr[px][py] == prev) { + continue; + } + + // 5칸 연속이라면, + if (cnt == 5) { + // 승리자 출력 + System.out.println(prev); + + // 가장 왼쪽에 있는 오목 출력 + if (j > ny - dy[k]) + System.out.println((nx - dx[k] + 1) + " " + (ny - dy[k]+ 1)); + else + System.out.println((i + 1) + " " + (j + 1)); + + return; + } + + } + } + } + } + System.out.println(0); + // 6개인지 검사 + } +} From 994e55bd5b0dabb3afbdde534ed9adeb827ef34c Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 30 Jan 2023 22:09:57 +0900 Subject: [PATCH 02/30] first commit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e69de29..7bd414c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +# soyeon From d91caa30988c2916848bb598cc13af35db12f2d0 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:41:15 +0900 Subject: [PATCH 03/30] Delete .project --- .project | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .project diff --git a/.project b/.project deleted file mode 100644 index 5cd108a..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - 알고리즘 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - From 3a76a15edb86a715465ca445379e3ae0801e1c0c Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:41:22 +0900 Subject: [PATCH 04/30] Delete .classpath --- .classpath | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .classpath diff --git a/.classpath b/.classpath deleted file mode 100644 index 57bca72..0000000 --- a/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - From 3c9f71dac8282289df10c6d4a962a03adae24aad Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:41:45 +0900 Subject: [PATCH 05/30] Delete bin directory --- .../BOJ_10972.class" | Bin 2033 -> 0 bytes .../BOJ_11051.class" | Bin 1423 -> 0 bytes .../BOJ_1269.class" | Bin 1734 -> 0 bytes .../BOJ_9375.class" | Bin 2457 -> 0 bytes .../BOJ_1120.class" | Bin 1398 -> 0 bytes .../BOJ_18111.class" | Bin 2267 -> 0 bytes .../BOJ_2503.class" | Bin 2008 -> 0 bytes .../BOJ_2615.class" | Bin 2330 -> 0 bytes 8 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.class" delete mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.class" delete mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.class" delete mode 100644 "bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.class" delete mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.class" delete mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.class" delete mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.class" delete mode 100644 "bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.class" diff --git "a/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.class" "b/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.class" deleted file mode 100644 index 670948612e4c236101c5cc286655995c6cd3e45a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2033 zcmaJ>Piz!r6#sp@GdtbsK%r$?`o~g0Wee>tZDA1#BITb8rHd4*6}3*g(=zRLb~Bwt z)Wm~wAmQY}m>4`1W2!f)rfsP9WMab2n+Fdj9!N}$iAO?Qf8T7|Eungt`QG>5`@Z*k zzxTfP;Gg?T0FEKAAtcbeeCy8gr{4`NPk;00CtnXO&wR`!(UU$m)Up5Yp-v5oz?O0A zx|PUU?pPu{JZ_Kp0%6PZ1VUF+0+FMR>-aBH7i%35P)_DDwvI3=4QQwksOoiGyRR@g zYwkC3w&t=KD2L0}nK27zs{)~8w1(T2E&c7d&Bu2QaV zkJ+Aq1orcayyZ>V)DiSbw4fnYc~3=LG7?q?B^$DL7g7fR0}DX}IuYk%LAw zkj6!Zxo%|(c6wB1n%a=~6p|I_7Z5EvQn+GZ0I%{*S^2!}W(3+d;`*rquHa$nDGVBT zJ*c^#D}j}KykX!?$+sG$%^WRnjE}8mgBQfk9Ol#BzQ*m7eb4tN`uOqTho)GA#**Jg zg_f=kYvp8aP#WiF32f^3t&xcfRz7(48iq7Ph==cjoa_C$f;VEHapaWPyf%d5l7H-E zjl!H<>_ypSl){ubV)&18m*6V6s(a_5-=h$M!G9!BZp9|bM#%x2QN>*pTdtcG29GeFB2i#CB>aJj#ZJ$N56e8`dX5l`GkJMJKk zFIl*+xS!>tzmEg>0SECTlK2US@PPZD(T#^VDg?SkB_qf>j+W|!w=l$AH6Gz@SgdUW z{>CsySkpHAh74?CPH=3DQl}8r5)nzMAG-scid)!=Yt*TXeQ8B{$a@^>A{giGXHivT za;k<24Ru087n`i=F=|9z=n)j-F*MOcDe@S)FpBIUeVr>?l1H*&z^EKA1SxyfA_&>b zb*xB3{FwanYmBGmzbRer-fB7mCy1qo-FlLop9&agDIE{8pabh5v*6%hM^91;QFf^h GA@?s2-_jBQ diff --git "a/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.class" "b/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.class" deleted file mode 100644 index d40e494f58efa04c3ab8e8660fb157842da6515d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1423 zcmaJ=&u<%55dOyA-50ytG;z8~nl!~NnAmNx>p%@OZGe=tb?d~XP9sG*q#OIyZ0fA7 z^%|94=>fzEA%rUR08*t0dVzov)JWX8@VA7203pJ>wG+2$gtTwp%$wie%>4Q9v)=(+ z!fk;N;l$48k9WTPb$RFepZ@yhhvl91ulUML7q2g8v**rd1vEn6s{M(bso8EdQ(Re< zWuIU)>}J`n5yDGLd1fy)tB#>4SGlcO@#GvOLSYI|& zStgJ*F`>dlTzTIQ5{Tk0-A6^o=!N=jVN;q8d?ee`@yAe#jz*QdE zQoZGsUL0XAf{cV4#xt3T~Ay^7=C71c6PUiez09yK%gyc1xmZN7HkVeOFtKvQdy+Zs(5yHfJ2wFo3m$0 zF<#ch8!v29Z4+ZcydavGXk(y}#vkCNH~s^!@DG?qeCF&2i=r22X3qOQ@AotF%U?hJ z4B#SWBzyvG8=ri+@x_nR8_VDS@#vfBjg`;1#fHa5rca;gKQG}I*gJ17nz5{D&&I}5 z^D6BM1O_eJa)$)!y1FL?{FieX6-FIG2I>(I*pskqb+fpTQqF{#$|`}zL@sS+Cr!uF z|7D@yowEu89f|)bjfQN+#(#mOVS569`|upH_L-%Gm{pMuCWjvU0Kb zSXCpjpB^fT;o{7Ua#UtqnHl9sGzm0Uba6Xhbm?803ng_32hk$Yysa0>rGl##47B1U z0iRAUT1rlb-SRLHMilM3FC790yLNGCzBV=HKefIbs4vwwCle&7Tl)iC>)GFtaQu;v+Tqa-%iQ;%5>w zXXbfIvBlf3=2E_LJn3GfvHd_3{V;41kS<1V<@_pBlKgQpI2)oP#tySN%90QUy|g|HiY=wvU? zeron(jw?tyzvAf+N@xA zRYWIJL}k>!y!q=>TyCyk#r0?)vx+x$^?vB;C;5PYRW`E9cCN>H*<+NQ!vS0&l}FHw zBwFx3&$DR5JW-42z(+WQk8uPKd7U5OC?3=DYs$Yv57yD^bu;g+&+!(<8KV*3($fU{ z*p9F8HY59J^Eqzg9gZu8Pcg-lpOGKn4(_tc*BRqo$^x|8h4*-pj6cp?v}_4yJ*{LO z?U<%4hz}S?&#>gfq>mIO#}L?LAyOhO5s~N=LZXjTZ+d|i@dB;lPlPpBG6ege{s#Oa BncDyW diff --git "a/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.class" "b/bin/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.class" deleted file mode 100644 index 2bf6081b230df813b756f23fe9ae8c5173bab945..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2457 zcmaJ@O>k3H6#j0S^d{j|pb*+n{-w}DAp$l)0u@_9f-MDFTM9~fOhB?UAd6@-It_E_*>-N_wG6OJLi1o=jP`- z-+d2YFD^+q1Xj*oygd8)xBatMzxnI4ulr{wE^!I8b{^{Ay<=yygi~PA8GTF-#P!5b zpmX4i5w!#=_m~OOY7wYtXzUSiwk2bR7ZvbmaG_FQVY`_y4rfOPjC8j?5H|#>+mlf} z-lL~Y^_|~zTEk{WV0HULoe0ywsBR_%mNlGgFFMm@rOm`pSUKR`e=cgIEHjzNNK_NC zsFm~LKr%h5Tk~2HO9htLN@g+;=`0Z}qnU!BH9I(Hq>b1yLysA0iCO`FK^94*vKC!1 z^wFHygXLHuQCCJ-*LcPGm!=p-R zJ)JKq<;;@@i46iZ#n5vEwPwvYz4xLX9)-}TVG}kBxaoRK!12#E!!8tYyXn2ldQwho16cJ3JD>0-d%j zcc?o#VkFG-%HL+}Qo-(i066JrMp(lh6^tigoU`n+3($gn5>E(J*>2m|w5j1qw6b7_ z40^kv)Z1K9hf68QZz&3%(y$)~1mu_=&l;VBstO~ex_L^%%J4xA5geiw)`q~Y`&cRA z`QdikHFV%GIW`kkk1}mHTSQqoqTwixu?uaN*g&;~{Mo^_CF5~+DVu>lb%SN`EK^)0 zqbS$Vi{r|KWu$d0nO3poL$i@0`F-M?z;hBO*~dkkf>guvIK>`SDY(0q@-eFOr#0vp zAd$m*=CG~G;c-HhWlVzs5?iUKQbr;su%evdvN{gCF)Sdw>fjl5a718BDba=ED`C1E zKs72`GJzy1O{zo{d-4cJO1`VvlP`edgsjX@iW0E~3t0hIN}af?L<^Z!qft)}F+)r4 zGq^Yq1_)j|-|gk&hGWl>Az%In20|LT`HN7|iZYf_J*7r(F+(hSq6k)zFclj8tSb@U z)p1m<7%|4xthOOaTbap88<}jJ2x5$7Qa;VcQ-z5hEPJ@+D&>=Zhug_f(jEIm5H zBlguGaaQ7^@=0n>dye|9WHuc&4w&jzsVZDlTb0LH3x>eU4RG*{HxZwbUjeRyt83E~ z+}CWemro@ImSO>)T26s$6~8=q1PckW$kuXTF_tJG$5Dc+lmE=X*EfTjzU%N$Vf7T& zwa=iwZwebbHcz7A2AW!&LFWW+&0srs9}l_m+ri3;pq#+*88r8)ttspbx&7`*gnI2~ z$m4hUJ=56hz>iq0-YagPZ5mHkpjUm(OK)MzB%X1eo|j&b!Y6%|SLY_2LFso*qf=lS zT>>G`1nLxKpFr+Z&`nLZ^Ykzkx!*7F#oX;CpLE715$$cN9-4&Nd%-Du&Xr%z?YoY6 z(0{eK|bzl{`u$pbZ7K7BVupXaMb{QLS z1&z4LJLo5_zjDI_w(#9e%+} zc$xXG#}9agZ%&@QhF9?#lN7>Nc%6Hd{G-#4H~1#$(|){(3vkn`U3d#`GtF1fhIee~ zO@3YEn;Y-aqAG_R+IvKMpF2H}a}3iZ@qvU-qF%6g?x04ZMTq~fLxTU7KKvJJ=IEri YM9Ws7`4d3R94RPApq-D2?!YJi16Y7*=Kufz diff --git "a/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.class" "b/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.class" deleted file mode 100644 index e9f557abccecbc1c4263477b547d2658407d950c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1398 zcmZuxU2hvj6g}gwS(^gIoTSugq=-tev8Tx<_S#yn zQ9(#N)I9J2;*}=~s?_K9!I6m6AHW~rPlP{E3CtNgAB`Hxo|!x6&b@ceJ+puP_vdo} z*Rd=S5U_TBZSOp4|MT#dorgbW^NY8>oSeKgArTT7+OWU2vsK$&%Py{NsIo5*x#qZz ze?uUc&MXUrX6h9cLl99DVMGK5i;k-nTD4W>E!nG8B@i#x%XW3y_8e{RZif7IrztQ} zJTmzd1J`WF6*!juqIgh5$@d(0ZAvGO%|0lrhVRtfrbJvI(erZZ*}~#JA~DPedqBQ* z|Gx56<&Lr|%9A)Ikle!xZlmQhy0UA1IEv#qA(1@9LFt>OuWBYnaZ(_l%d`5$>9hwC zred%#ruleF;CT8-m&|eu37pnWXIT7!Q$IbgDDn1Qfi2&uX8U(vs&6XS`Br)Q_*oP0 zA}wIB?uzDJU^tz5m9H35IHyycXT`gzdQIKuQ+te?xTvE=UG>246W4H^cD+Ua1NLsS zue0VI@#(fhMaN z?c+z0O&2k(mHdhn3FLX5nihj7@bA!a>kKD01O`gJUEZ9x8$H!a%u=_dddn-TIY&Q@ zfxXvuQ3u9p@GxH{5a5c>iKC>IpH4MCt*EpJe2hIbuqTC&1kRh%^ zMBdP0M3W(--1&JMiIr_wE6*^pg*Ufws<@5R%J~l7*+ORiLI)QX^l&v4&*s9xT;vJn zf;kz?8BcI_+%h_tNQSJ4WqifeZ-}&|u%s1!3_1?B4PhDM9prxR{;hZafV5;T+>Qt< zk_>TQW0l9KVl%PT~$d z?$KVyDKv@yfHU}sCo~uL`nSYQ%+iYEJIvt|vM`1QK1G4Nq_Bxw_>6foP$+U0Vip_o zSRh9exXT<1pnNJyk4CixTW$GIZYZ91MZMEY26988A?+OX(;WF{geE}6CO$j zhD9t8m5{n%0|==RL)hY=q#_b4xMKju^(S8QMYE*{j6IFDs1X##hi9q@7m(tT_%DQD{<@GKN0X#3@Vcc<IFtzfwBou&8M_@Nkd3_t4o9ZYoJDRUmcT{zxPuvnX&u!z=R0l}QwGvT(y1F5y*jG+mH!RSR%|?5R|_N5yLb zn^&JzPDQw2B}fi0Mlh=4^3&C~$*18BToF*O8;OEBG%lYVshRR9f*xFB6YcOKiZKl_ z#2L1c$(Sh$2Wr*fnbK9_A)}%gmo6p*T518VHMBHL*|f-~%dhexfs~5mnl4$B3JqyV z3?(D8!z>!v3Fdc0jlLu4$Fj0(SK8+3mSWdBa`ez#KCi`Enh1;ElpH#;fy5*~&Xx7U zc_TJGU}P!-!aJNUWMk$TOOBBG>ICbO$k@rEJ2~#$@JQZJ@<@W&E9qsgB$vICNcKt^ zadq(~=M?`9+y%G_uFC#JG=4|HfhPXlw$g(Ql(n(}HbUpF4x6xO>ac~~Ts#0H7I#I&068awCq+=eZ zoV{}huD$CFx#pmkaH=(^yDFE4iY}qMcxiU|&!SVb(!=cXFHL89Y3vLsbGYrC$Jr82 z%p>9qx#w`+8B*tPgkE%aP*=NjdJkbpM$m{4;59Rt2We6MYqu1 zHr6~L&(6YELgaI-qui@2Ay-imy5bXJc6p|Ri%W=(wBE<-i+Ho?>H-YiwE%MglM9%Z z33u8F|9}+*e3YB8ovHRS*+HiIC=(sQHVkssT}BJ8ajvGh-lDF^KL3#S?w}2KIgvlX zZhVG4xQD&?2K(?my)2>~53nDt;izBQg0VNpsSeZKvQ1 z4BK{Ye2Fllmu$UF@13ZBf?Q1=Ke4w8>kj*&>_ zTBMxpfL+Xe3+uNn*xVJ5v(T)9tE!m1Mgpwzy57EW1dSZsZA`A@_l~j~J3MZgNEx1N rid}Z_5|(qf3hS!ER#02w1d*^xRZ$bRkFduHd*Xk>3cSN09C-I%i#zD8 diff --git "a/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.class" "b/bin/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.class" deleted file mode 100644 index 1c6b809793effe4a1b66bd93aba05a5da03183d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2008 zcmZuxO>7iZ9RIz}?9R?~w!4%L6tKvLK+8uLD4mLwf_&-XLXnnAL4oOZ+D^OOU1oO) z9~Z@5OiVQKgqPOD*ozmdQeugT7d2iy=t&PIMo(hAc+n8+@6B{u(C%j5`@R3y`+vS~ z{`u^400%Lkp+>-ZaA)Gd)Wq+vzy09#H&REsPhQ^JzPn9>Dv%s?t~sfklOIlX4~)9m zvVh|FzCg{zv_P~}_PsGzKpk*$Ii5ScyjSj`Omj;gsYeTgt^oyc6FLlmM8?azrz_(F zuHWknL`ve6dodb=MgW z**c!UdJRpFrKjgcsqBuMcoG|!9qFDGIw!APvT(q_8f=pJ*euZ4ysSt|pMllbB89fn z`6Z$7dWI1}0rSoNX*!4}Mu$v}|j$d*~ zqtgqw1tqVhG_6BmuZakv674ggg~&D$LsY}l)pS+LUM>}?^%ln5ym!;}4Rqic84N48 zta*mhfrBQxWH@@>yih`X#B+FF zKr2d(9Lu6Mr-SBn{9!iP%4J%J^&4P|H!j}xcy}<2ni9QP7xI@2nIhseKhB8oI2XQK zs^qAm4&|I-(k}2D;YX6F@EfH}cErt&(bEw0R>3)HWf^O@F%|KivXdP<jaF%+b^(TV%<8FV#}&Iyu@f{^JB8>(ouD;y0qItJ0cn;w34=lbAt8lo zB_Xy*&_jYADksDY+Ih8=m_nV5ny_vXI%AqfLban4hOi9Ad&P?0;kBxmhzKjPLizFi zd1D5LEcGsq%GxQAwfle%1&HcdueDq^uwGkPubo(hy?jZ!(1;iKES)FUB`wdvyNV`U z$9mji1Kq|Zyot?thgvh(hEK5_bJ&3|Y2kb9!cS<$&upAuY3&cR;VmBPV!VQMo7=FtN1qH z6i&0x)`~0W#u>(z!Xdm!q~fa3aW+5|JPc?Ndj1=F(96!fjbCt%T#ZrufIgxaWBCp* z5$U+c{G2B;7|&biC#q#sui*lb$=I&pB2k4m{~Cy9xPcP5G#c%cdE>ihL)KcOx=-+9mb|32^g zz5RCStA_yk@IHr)K|H-S^K^FR_p2X2z50=VAbjjxS71*!hr&=fpd8w^#UL{yIt=_ylw z7nw@>ygAKK8!8*TmmE*&rp2(nc{sF^#9%sQTI0PkuzKWD)JUeygf-1k#ZaBsG86t_ zcv-?xLmocyD(?k)o>HT)WO zOK)z=xRlPvQPG9H94|4fTWLnnN*m)wN<%jS6gsJ=rVZl#kLRF7^kohE(L-e=GE#3D znUmDkBK!p20ldP|x2mP9#2OCb5Ccz2i#T;aX%0%P256R6QY(}*kTK)bX%(;HD94et zt;|o7hS%^qdAp#;Ge&q!rXDN{TR+-ec!Pm$Rnd>*8crZgcR^1k4J*dbQ4Y%&;4kJw z753vz>EaZ_rg8ySE1uSHCg0k0qEMB@=Pd~X^-$4M<8+Iv%iIwf(9sl)-!jH)$DeMP zZJK&eUyzp@EK;%SDe_^9U7}++D5=YYfk_X2unBr5NhvCuZnLD4MRFyXGA0eP71n+owEBD)slL@D!zL%EFl-ev((C$=j!dE06v+R&P;F@Q9m4I6~ z>lESY90{m`*E#Z(r>Gaugj!iW$5f$SXAa>Z8cV`+1O4;(bH>etx@_txnF_b-HYn}Z zyeS&V6b%K_T4_q6iVmT62~VfcZsr~o!^Z;NV)$6VC%o6uB)l?QgYaEPo$yJzszZ3Y zgpcfIrJFQ`nuT=_`-GN7ui&DPMC>-YiMfdWNHM{fGIAe>7Z9vEmPM$fri^59GK;}1 zhUT%eWZ_(^%U5aLopCYY;zeL(a?>Xrog_70pRKO-VaV zL?6w^Vd8{orJg|zqV%33-bGqnAD|9bN%I;u<0cv~hb_2+t;o`_KEif9K_h;|PW*&j z_yx^)MjQDrwBkA1SQXltKoi@B-K-6JSU0*@gtqBf>|>+Y&n9qyU8IfoIS#VN=x5(y zGy8#ldw#|S_A4!@XE>Ih?K_kUO)cI=gmSMU`8ybf|df1QVoW GL-Id6{Qdp_ From cc2004936958e23801d6498ca39f4bb5732ca955 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:41:52 +0900 Subject: [PATCH 06/30] Delete .settings directory --- .settings/org.eclipse.jdt.core.prefs | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .settings/org.eclipse.jdt.core.prefs diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 8c9943d..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,14 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=17 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning -org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=17 From 928dd3dc694786be2565de3aac3081d95b40f2d4 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:46:01 +0900 Subject: [PATCH 07/30] =?UTF-8?q?Rename=20src/=EC=88=9C=EC=97=B4=5F?= =?UTF-8?q?=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9/BOJ=5F1269.java=20to=20?= =?UTF-8?q?=EC=88=9C=EC=97=B4=5F=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9/BO?= =?UTF-8?q?J=5F1269.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_1269.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" => "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" (100%) diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" "b/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" similarity index 100% rename from "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" rename to "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_1269.java" From a4f22b8c99d0e967f3ae5e0575d0d11a7f428a9f Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:47:14 +0900 Subject: [PATCH 08/30] =?UTF-8?q?Rename=20src/=EC=88=9C=EC=97=B4=5F?= =?UTF-8?q?=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9/BOJ=5F10972.java=20to?= =?UTF-8?q?=20=EC=88=9C=EC=97=B4=5F=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9?= =?UTF-8?q?/BOJ=5F10972.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_10972.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" => "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" (100%) diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" "b/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" similarity index 100% rename from "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" rename to "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_10972.java" From e7f10e524fa49e608bfa9da85b846eacb5124c9e Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:48:18 +0900 Subject: [PATCH 09/30] =?UTF-8?q?Rename=20src/=EC=88=9C=EC=97=B4=5F?= =?UTF-8?q?=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9/BOJ=5F11051.java=20to?= =?UTF-8?q?=20=EC=88=9C=EC=97=B4=5F=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9?= =?UTF-8?q?/BOJ=5F11051.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_11051.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" => "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" (100%) diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" "b/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" similarity index 100% rename from "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" rename to "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_11051.java" From b3e255672f509ffedcee61e1164291ab829311f8 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:48:41 +0900 Subject: [PATCH 10/30] =?UTF-8?q?Rename=20src/=EC=88=9C=EC=97=B4=5F?= =?UTF-8?q?=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9/BOJ=5F9375.java=20to=20?= =?UTF-8?q?=EC=88=9C=EC=97=B4=5F=EC=A1=B0=ED=95=A9=5F=EC=A7=91=ED=95=A9/BO?= =?UTF-8?q?J=5F9375.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_9375.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" => "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" (100%) diff --git "a/src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" "b/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" similarity index 100% rename from "src/\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" rename to "\354\210\234\354\227\264_\354\241\260\355\225\251_\354\247\221\355\225\251/BOJ_9375.java" From 1b15d67e0c01fff43ee0ae8d5160986e2e53eec2 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:49:03 +0900 Subject: [PATCH 11/30] =?UTF-8?q?Rename=20src/=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F1120.java=20to=20=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F1120.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_1120.java" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" => "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" (99%) diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" similarity index 99% rename from "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" rename to "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" index 1050108..3011130 100644 --- "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" +++ "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" @@ -33,4 +33,4 @@ public static void main(String[] args) throws IOException { } System.out.println(min); } -} \ No newline at end of file +} From 7b291a9b4a96f537a380e902a288c6f9fd169b56 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:49:23 +0900 Subject: [PATCH 12/30] =?UTF-8?q?Rename=20src/=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F18111.java=20to=20=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F18111.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_18111.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" => "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" (100%) diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" similarity index 100% rename from "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" rename to "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" From 1863b0c041d64058f8271c620322a1268e8f66e6 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:49:42 +0900 Subject: [PATCH 13/30] =?UTF-8?q?Rename=20src/=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F2503.java=20to=20=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F2503.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_2503.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" => "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" (100%) diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" similarity index 100% rename from "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" rename to "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" From 862d05a7826ed640600680cfb5d79648de38fe78 Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:49:57 +0900 Subject: [PATCH 14/30] =?UTF-8?q?Rename=20src/=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F2615.java=20to=20=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89/BOJ=5F2615.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_2615.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" => "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" (100%) diff --git "a/src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" similarity index 100% rename from "src/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" rename to "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" From b8a07b0e0df07b5e13f635eeaa81c3fb278ac941 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 6 Feb 2023 21:03:29 +0900 Subject: [PATCH 15/30] =?UTF-8?q?2=EC=9B=94=201=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\203\235\354\210\230\354\227\264.java" | 40 +++++++++++ ...\355\202\244\353\241\234\352\261\260.java" | 56 +++++++++++++++ ...\354\227\220\353\224\224\355\204\260.java" | 49 +++++++++++++ ...\353\217\204\352\263\265\354\202\254.java" | 68 +++++++++++++++++++ .../BOJ_13335_\355\212\270\353\237\255.java" | 49 +++++++++++++ ...\354\225\265\353\254\264\354\203\210.java" | 57 ++++++++++++++++ .../BOJ_1068_\355\212\270\353\246\254.java" | 5 ++ ...\353\246\254\354\210\234\355\232\214.java" | 7 ++ 8 files changed, 331 insertions(+) create mode 100644 "\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" create mode 100644 "\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" create mode 100644 "\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" create mode 100644 "\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" create mode 100644 "\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" create mode 100644 "\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" create mode 100644 "\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" create mode 100644 "\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" diff --git "a/\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" "b/\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" new file mode 100644 index 0000000..2c588af --- /dev/null +++ "b/\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" @@ -0,0 +1,40 @@ +package 스택; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +/** + * + * stack : + * 1. 현재 수열 값 >= 자연수 : push + * 2. 현재 수열 값 < 자연수 : pop + */ +public class BOJ_1874_스택수열 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + Stack stack = new Stack(); + int N = Integer.parseInt(br.readLine()); + int index = 1; // 자연수 + for (int i = 0; i < N; i++) { + int num = Integer.parseInt(br.readLine()); // 현재 수열 값 +// * 1. 현재 수열 값 >= 자연수 : push + if (num >= index) { + while (num >= index) { + stack.push(index++); + sb.append("+\n"); + } + } +// * 2. 현재 수열 값 < 자연수 : pop + else if (stack.peek() > num) { // 스택 맨 위의 수보다 큰 자연수는 찾을 수가 없음. + System.out.println("NO"); + return; + } + stack.pop(); + sb.append("-\n"); + } + System.out.println(sb); + } +} \ No newline at end of file diff --git "a/\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" "b/\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" new file mode 100644 index 0000000..a618301 --- /dev/null +++ "b/\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" @@ -0,0 +1,56 @@ +package 스택 +; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; +/** + * + * 커서를 가운데에 놓고 좌우 stack 이동 + * + */ +public class BOJ_5397_키로거 { + char left = '<'; + char right = '>'; + char back = '-'; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + int T = Integer.parseInt(br.readLine()); + + for (int tc = 0; tc < T; tc++) { + Stack left = new Stack(); + Stack right = new Stack(); + String s = br.readLine(); + String[] input = s.split(""); + for (int i = 0; i < input.length; i++) { + switch (input[i]) { + case "<": + if(!left.isEmpty()) + right.push(left.pop()); + break; + case ">": + if(!right.isEmpty()) + left.push(right.pop()); + break; + case "-": + if(!left.isEmpty()) + left.pop(); + break; + default: + left.push(input[i]); + } + } + + while(!left.isEmpty()) { + right.push(left.pop()); + } + while(!right.isEmpty()) { + sb.append(right.pop()); + } + sb.append("\n"); + } + System.out.println(sb); + } +} diff --git "a/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" new file mode 100644 index 0000000..625de16 --- /dev/null +++ "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" @@ -0,0 +1,49 @@ +package 연결리스트; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +public class BOJ_1406_에디터 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + Stack left = new Stack(); + Stack right = new Stack(); + String s = br.readLine(); + String[] srr = s.split(""); + for (int i = 0; i < s.length(); i++) { + left.add(srr[i]); + } + int M = Integer.parseInt(br.readLine()); + for (int i = 0; i < M; i++) { + String[] input = br.readLine().split(" "); + switch (input[0]) { + case "L": + if(!left.isEmpty()) + right.push(left.pop()); + break; + case "D": + if(!right.isEmpty()) + left.push(right.pop()); + break; + case "B": + if(!left.isEmpty()) + left.pop(); + break; + default: + left.push(input[1]); + break; + } + } + + while(!left.isEmpty()) { + right.push(left.pop()); + } + while(!right.isEmpty()) { + sb.append(right.pop()); + } + System.out.println(sb); + } +} diff --git "a/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" new file mode 100644 index 0000000..38d3c35 --- /dev/null +++ "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" @@ -0,0 +1,68 @@ +package 연결리스트; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.StringTokenizer; + +public class BOJ_23309_철도공사 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + LinkedList list = new LinkedList(); + int N = Integer.parseInt(st.nextToken()); // 역의 개수 + int M = Integer.parseInt(st.nextToken()); // 공사 횟수 + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + list.add(i, Integer.parseInt(st.nextToken())); + } + + int idx; + int jdx; + int change; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine(), " "); + String key = st.nextToken(); + switch (key) { + case "BN": + idx = Integer.parseInt(st.nextToken()); + jdx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)+1; + + if(change >= list.size()) {change = 0;} + sb.append(list.get(change)+"\n"); + list.add(change, jdx); + break; + case "BP": + idx = Integer.parseInt(st.nextToken()); + jdx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)-1; + if(change < 0) {change = list.size() - 1;} + sb.append(list.get(change)+"\n"); + list.add(change+1, jdx); + break; + case "CN": + idx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)+1; + if(change >= list.size()) {change = 0;} + sb.append(list.get(change)+"\n"); + list.remove(change); + break; + case "CP": + idx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)-1; + if(change < 0) {change = list.size() - 1;} + sb.append(list.get(change)+"\n"); + list.remove(change); + break; + default: + break; + } + } + System.out.println(sb); // 시간초과;; + } +} diff --git "a/\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" "b/\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" new file mode 100644 index 0000000..151d70d --- /dev/null +++ "b/\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" @@ -0,0 +1,49 @@ +package 큐; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class BOJ_13335_트럭 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + Queue queue = new LinkedList(); + Queue bridge = new LinkedList(); + + int N = Integer.parseInt(st.nextToken()); + int W = Integer.parseInt(st.nextToken()); + int L = Integer.parseInt(st.nextToken()); + + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + queue.offer(Integer.parseInt(st.nextToken())); + } + + for (int i = 0; i < W; i++) { + bridge.offer(0); + } + + int l = 0; // 무게 + int time = 0; // 시간 + + while (!bridge.isEmpty()) { + time++; + l -= bridge.poll(); // 다리에서 빠져 나감 + if(!queue.isEmpty()) { + // 다리 위를 지나갈 수 있는 경우 + if(queue.peek() + l <= L) { + l += queue.peek(); + bridge.offer(queue.poll()); + }else { + bridge.offer(0); + } + } + } + System.out.println(time); + } +} diff --git "a/\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" "b/\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" new file mode 100644 index 0000000..163a67e --- /dev/null +++ "b/\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" @@ -0,0 +1,57 @@ +package 큐; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; +/** + * + * 큐리스트 + * + */ +public class BOJ_14713_앵무새 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + Queue check = new LinkedList<>(); + Queue arr[]; + int N = Integer.parseInt(br.readLine()); + arr = new LinkedList[N]; + int sum = 0; + for (int i = 0; i < N; i++) { + arr[i] = new LinkedList(); + String s = br.readLine(); + String[] srr = s.split(" "); + sum+= srr.length; + for(int j = 0; j < srr.length; j++) { + arr[i].offer(srr[j]); + } + } + + String a = br.readLine(); + String[] ans = a.split(" "); + + // 반례 : 받아적은 문장과 앵무새가 말한 단어의 개수가 다를 때. + if(sum != ans.length) {System.out.println("Impossible"); return;} + + boolean flag = false; + for (int i = 0; i < ans.length; i++){ + flag = false; + for (int j = 0; j < N; j++) { + if(ans[i].equals(arr[j].peek())) { + arr[j].poll(); + flag = true; + break; + } + } + if(!flag) break; + } + + if(flag) System.out.println("Possible"); + else System.out.println("Impossible"); + + } // end of main +} // end of class diff --git "a/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" "b/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" new file mode 100644 index 0000000..4979444 --- /dev/null +++ "b/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" @@ -0,0 +1,5 @@ +package 트리; + +public class BOJ_1068_트리 { + m +} diff --git "a/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" "b/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" new file mode 100644 index 0000000..80a7568 --- /dev/null +++ "b/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" @@ -0,0 +1,7 @@ +package 트리; + +public class BOJ_1991_트리순회 { + public static void main(String[] args) { + Tree + } +} From a5df2e62131924f24d94cf39dc16d452d6623ffb Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 6 Feb 2023 22:15:04 +0900 Subject: [PATCH 16/30] =?UTF-8?q?2=EC=9B=94=201=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_1068_\355\212\270\353\246\254.java" | 66 ++++++++++++++++++- ...\353\246\254\354\210\234\355\232\214.java" | 61 ++++++++++++++++- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git "a/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" "b/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" index 4979444..fb4fc1d 100644 --- "a/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" +++ "b/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" @@ -1,5 +1,69 @@ package 트리; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + public class BOJ_1068_트리 { - m + + static int[] tree; + static ArrayList child[]; + static int cnt = 0; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + int root = 0; + tree = new int[N]; + child = new ArrayList[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + child[i] = new ArrayList(); + } + for (int i = 0; i < N; i++) { + tree[i] = Integer.parseInt(st.nextToken()); + if(tree[i] == -1) { // 부모노드가 없으면 루트노드 + root = i; + continue; + } + child[tree[i]].add(i); // 자식 노드에 부모 노드 정보 + } + + int del = Integer.parseInt(br.readLine()); + + // 루트노드를 지우는 것이 아니라면, + if(del != root) { + delete(del); + search(root); + }else { + System.out.println(cnt); + return; + } + System.out.println(cnt); + + + } + public static void search(int node) { + // 자식이 없으면 리프노드 + if(child[node].size() == 0) { + cnt++; + return; + } + // 자식까지 탐색 + for (int i = 0; i < child[node].size(); i++) { + search(child[node].get(i)); + } + } + + public static void delete(int del) { + for (int i = 0; i < child[tree[del]].size(); i++) { + if(child[tree[del]].get(i) == del) { + child[tree[del]].remove(i); + break; + } + } + } + } diff --git "a/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" "b/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" index 80a7568..76f0edd 100644 --- "a/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" +++ "b/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" @@ -1,7 +1,64 @@ package 트리; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + public class BOJ_1991_트리순회 { - public static void main(String[] args) { - Tree + static int[][] tree; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + tree = new int[26][2]; + + + for (int i = 0; i < N; i++) { + String[] temp = br.readLine().split(" "); + int node = temp[0].charAt(0) - 'A'; + char left = temp[1].charAt(0); + char right = temp[2].charAt(0); + if(left == '.') { // 왼쪽에 자식 노드가 없음 + tree[node][0] = -1; + }else { + tree[node][0] = left -'A'; + } + + if(right == '.') { // 오른쪽에 자식 노드가 없음 + tree[node][1] = -1; + }else { + tree[node][1] = right - 'A'; + } + } + preOrder(0); + sb.append("\n"); + inOrder(0); + sb.append("\n"); + postOrder(0); + sb.append("\n"); + System.out.println(sb); + } + /** 가운데 - 왼쪽 - 오른쪽 */ + public static void preOrder(int i) { + if(i == -1) return; // 자식노드가 없으면 종료 + sb.append((char) (i + 'A')); // 현재 + preOrder(tree[i][0]); // 왼쪽 + preOrder(tree[i][1]); // 오른쪽 + } + /** 왼쪽 - 가운데 - 오른쪽 */ + public static void inOrder(int i) { + if(i == -1) return; // 자식노드가 없으면 종료 + inOrder(tree[i][0]); // 왼쪽 + sb.append((char) (i + 'A')); // 현재 + inOrder(tree[i][1]); // 오른쪽 + } + /** 왼쪽 - 오른쪽 - 가운데 */ + public static void postOrder(int i) { + if(i == -1) return; // 자식노드가 없으면 종료 + postOrder(tree[i][0]); // 왼쪽 + postOrder(tree[i][1]); // 오른쪽 + sb.append((char) (i + 'A')); // 현재 } + } From 004e4e054bb3a31847bea210ecc07c8974e27c9f Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 13 Feb 2023 22:55:21 +0900 Subject: [PATCH 17/30] =?UTF-8?q?2=EC=9B=942=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\263\204\353\262\225\354\271\231.java" | 77 +++++++++++++++++++ ...\353\263\264\353\254\274\354\204\254.java" | 76 ++++++++++++++++++ ...\354\266\234\354\236\221\354\240\204.java" | 52 +++++++++++++ ...\352\263\240\353\245\264\352\270\260.java" | 50 ++++++++++++ ...\353\247\236\354\266\224\352\270\260.java" | 34 ++++++++ ...\354\213\244\353\260\260\354\240\225.java" | 40 ++++++++++ ...00_17829_222\355\222\200\353\247\201.java" | 51 ++++++++++++ ...\353\223\234\355\212\270\353\246\254.java" | 54 +++++++++++++ 8 files changed, 434 insertions(+) create mode 100644 "BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" create mode 100644 "BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" create mode 100644 "DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" create mode 100644 "DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" create mode 100644 "\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" create mode 100644 "\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" create mode 100644 "\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" create mode 100644 "\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" diff --git "a/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" new file mode 100644 index 0000000..6b1f78f --- /dev/null +++ "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" @@ -0,0 +1,77 @@ +package BFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +/** BFS */ +public class Main_백준_1389_케빈베이컨의6단계법칙 { + static int[][] list; + static boolean[] isVisited; + static int N, M, ans; + static StringBuilder sb = new StringBuilder(); + static int min = Integer.MAX_VALUE; + static class Friend{ + int node; // 탐색 시작 노드 + int count; // 친구 수 + public Friend(int node, int count) { + this.node = node; + this.count = count; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + list = new int[N+1][N+1]; + isVisited = new boolean[N+1]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[a][b] = 1; // 양방향 + list[b][a] = 1; + } + + //모든 노드에서 시작 + for (int i = 1; i <= N; i++) { + Arrays.fill(isVisited, false); + BFS(i); + } + System.out.println(ans); + } // end of main + + public static void BFS(int node) { + Queue queue = new ArrayDeque(); + queue.offer(new Friend(node, 0)); // 큐에 삽입 + isVisited[node] = true; // 방문 + int cnt = 0; // + while(!queue.isEmpty()) { + Friend friend = queue.poll(); // 맨 앞의 값 꺼내기 + cnt += friend.count; + + for (int i = 1; i <= N; i++) { + // list[node][ ] 전체 탐색 && 방문하지 않음 + if(list[friend.node][i] == 1&& !isVisited[i] ) { + isVisited[i] = true; + queue.offer(new Friend(i, friend.count + 1)); // 가중치 + 1 + } + } + } // end of while + if(min > cnt) { + min = cnt; + ans = node; + } + } // end of BFS +} // end of class diff --git "a/BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" "b/BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" new file mode 100644 index 0000000..56841a9 --- /dev/null +++ "b/BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" @@ -0,0 +1,76 @@ +package BFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; +import java.util.StringTokenizer; + +/** BFS */ +public class Main_백준_2589_보물섬 { + static int N, M, maxCnt; + static char[][] map; + static boolean[][] isVisited; + static int[] dx = {-1, 0, 1, 0}; + static int[] dy = {0, -1, 0, 1}; + + static class treasureMap{ + int x; + int y; + int count; + public treasureMap(int x, int y, int count) { + this.x = x; + this.y = y; + this.count = count; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + map = new char[N][M]; + for (int i = 0; i < N; i++) { + String s = br.readLine(); + for (int j = 0; j < M; j++) { + map[i][j] = s.charAt(j); + } + } + + // 지도 탐색 + int ans = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if(map[i][j] == 'L') { // 육지일 때만 탐색 + isVisited = new boolean[N][M]; + BFS(i, j); + ans = Math.max(ans, maxCnt); // 최대값과 비교 + } + } + } + System.out.println(ans); + } // end of main + + static void BFS(int posX, int posY) { + Queue queue = new ArrayDeque(); + queue.offer(new treasureMap(posX, posY, 0)); + isVisited[posX][posY] = true; + maxCnt = 0; + while(!queue.isEmpty()) { + treasureMap t = queue.poll(); + for (int i = 0; i < 4; i++) { + int nowX = t.x + dx[i]; + int nowY = t.y + dy[i]; + // 범위 내의 이동 && 방문하지 않음 && 육지 + if(nowX >= 0 && nowX < N && nowY >= 0 && nowY < M && !isVisited[nowX][nowY] && map[nowX][nowY] == 'L') { + isVisited[nowX][nowY] = true; + queue.offer(new treasureMap(nowX, nowY, t.count + 1)); // 가중치 + 1 + maxCnt = Math.max(maxCnt, t.count + 1); // 해당 시작점에서 가장 먼 곳 찾기 + } + } + } // end of while + } // end of BFS +} // end of class diff --git "a/DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" "b/DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" new file mode 100644 index 0000000..1509288 --- /dev/null +++ "b/DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" @@ -0,0 +1,52 @@ +package DFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** 후위 순회 트리 */ +public class Main_백준_16437_양구출작전 { + static int N; + static ArrayList Island[]; // 트리 저장 + static long[] animalCnt; // 동물 수 저장 + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + Island = new ArrayList[N+1]; + animalCnt = new long[N+1]; + for (int i = 1; i <= N; i++) { + Island[i] = new ArrayList(); + } + + for (int i = 2; i <= N; i++) { + st = new StringTokenizer(br.readLine(), " "); + char animal = st.nextToken().charAt(0); + int count = Integer.parseInt(st.nextToken()); + if(animal == 'W') { // 늑대 수는 음수 + count *= -1; + } + animalCnt[i] = count; + int bridge = Integer.parseInt(st.nextToken()); + Island[bridge].add(i); + } + + DFS(1, 0); + System.out.println(animalCnt[1]); + } // end of main + + public static void DFS(int now, int prev) { + for (int next : Island[now]) { + DFS(next, now); + } + if(prev == 0) { // 루트노드면 종료 + return; + } + if(animalCnt[now] > 0) // 양이면 부모 노드에 sum + animalCnt[prev] += animalCnt[now]; + } +} // end of class diff --git "a/DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" "b/DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" new file mode 100644 index 0000000..aed412a --- /dev/null +++ "b/DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" @@ -0,0 +1,50 @@ +package DFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class Main_백준_2668_숫자고르기 { + static int[] arr; + static boolean[] isVisited; + static ArrayList list = new ArrayList(); + static int N; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + N = Integer.parseInt(br.readLine()); + arr = new int[N+1]; + for (int i = 1; i <= N; i++) { + arr[i] = Integer.parseInt(br.readLine()); + } + isVisited = new boolean[N+1]; + for (int i = 1; i <= N; i++) { + Arrays.fill(isVisited, false); + DFS(i, i); + } + Collections.sort(list); + sb.append(list.size()).append("\n"); + for (Integer i : list) { + sb.append(i).append("\n"); + } + System.out.println(sb.toString()); + } // end of main + + public static void DFS(int node, int target) { + // 사이클이 같을 때 추가하고 종료 + if(arr[node] == target) { + list.add(node); + return; + } + // 사이클 X + if(isVisited[node]) { + return; + } + // 사이클 재귀 + isVisited[node] = true; + DFS(arr[node], target); + } // end of DFS +} // end of class diff --git "a/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" new file mode 100644 index 0000000..79faa2f --- /dev/null +++ "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" @@ -0,0 +1,34 @@ +package 그리디; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_11509_풍선맞추기 { + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + int[] balloon = new int[N+1]; + int[] arrow = new int[1000001]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + balloon[i] = Integer.parseInt(st.nextToken()); + } + int cnt = 0; + int height = 0; + for (int i = 1; i <= N; i++) { + height = balloon[i]; + // 맞춘 적이 없다면 + if(arrow[height] == 0) { + arrow[height-1]++; // 다음에 와야할 풍선 높이에 check + cnt++; // 화살++ + }else { // 맞춘 적이 있다면 + arrow[height]--; // 맞춰서 check 풀기 + arrow[height-1]++; // 다음에 와야할 풍선 높이에 check + } + } + System.out.println(cnt); + } +} diff --git "a/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" new file mode 100644 index 0000000..93f9e06 --- /dev/null +++ "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" @@ -0,0 +1,40 @@ +package 그리디; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; +import java.util.StringTokenizer; + +public class Main_백준_1931_회의실배정 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int N = Integer.parseInt(br.readLine()); // 회의 수 + int[][] arr = new int[N][2]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + arr[i][0] = Integer.parseInt(st.nextToken()); // 시작 시간 + arr[i][1] = Integer.parseInt(st.nextToken()); // 종료 시간 + } + + // 회의 종료 시간이 빠른 것부터 정렬 + Arrays.sort(arr, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if(o1[1] == o2[1]) return o1[0] - o2[0]; // 종료시간이 같으면 시작시간 정렬 + return o1[1] - o2[1]; // 오름차순 + } + }); + int ans = 0; + int time = 0; + for (int i = 0; i < N; i++) { + if(time <= arr[i][0]) { // 끝나는 시간과 같거나 큰 다음 시작 시간이 있다면, + time = arr[i][1]; + ans++; + } + } + System.out.println(ans); + } +} diff --git "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" new file mode 100644 index 0000000..2821431 --- /dev/null +++ "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" @@ -0,0 +1,51 @@ +package 분할정복; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_17829_222풀링 { + static int[][] pool; + static int N; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + pool = new int[N][N]; + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + pool[i][j] = Integer.parseInt(st.nextToken()); + } + } + System.out.println(Pooling(N, 0, 0)); + + } // end of main + public static int Pooling(int N, int x, int y) { + if(N == 2) { + return FindSecond(N, x, y); + }else { + int[] arr = new int[4]; + int N2 = N/2; + arr[0] = Pooling(N2, x, y); + arr[1] = Pooling(N2, x + N2, y); + arr[2] = Pooling(N2, x, y + N2); + arr[3] = Pooling(N2, x + N2, y + N2); + Arrays.sort(arr); + return arr[2]; // 두 번째로 큰 수 + } + } + public static int FindSecond(int N, int x, int y) { + int[] arr = new int[4]; + int idx = 0; + for (int i = x; i < x + 2; i++) { + for (int j = y; j < y + 2; j++) { + arr[idx++] = pool[i][j]; + } + } + Arrays.sort(arr); + return arr[2]; // 두 번째로 큰 수 + } +} diff --git "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" new file mode 100644 index 0000000..78ac9ed --- /dev/null +++ "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" @@ -0,0 +1,54 @@ +package 분할정복; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_1992_쿼드트리 { + static int[][] arr; + static int N; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + arr = new int[N][N]; + for (int i = 0; i < N; i++) { + String str = br.readLine(); + for (int j = 0; j < N; j++) { + arr[i][j] = str.charAt(j) - '0'; + } + } + QuadTree(N, 0, 0); + System.out.println(sb.toString()); + } // end of main + + public static void QuadTree(int N, int x, int y) { + if(N < 1) return; // 더이상 쪼갤 수 없으면 return + if(check(N, x, y)) { // 모두 1이거나 0이면 만족 + if(arr[x][y] == 1) { + sb.append(1); + }else + sb.append(0); + }else { + sb.append("("); + int N2 = N/2; + QuadTree(N2, x, y); // (0, 0) + QuadTree(N2, x, y + N2); // (0, 1) + QuadTree(N2, x + N2, y); // (1, 0) + QuadTree(N2, x + N2, y + N2); // (1, 1) + sb.append(")"); + } + + } // end of QuadTree + public static boolean check(int N, int x, int y) { + int color = arr[x][y]; // 맨 처음 색상 + for (int i = x; i < x+N ; i++) { + for (int j = y; j < y+N; j++) { + if(arr[i][j] != color) + return false; + } + } + return true; + } // end of check +} // end of class From 305665c855c9f253bd3a3b054d5a8882fecb7dab Mon Sep 17 00:00:00 2001 From: soyeon <99261393+soyeon37@users.noreply.github.com> Date: Tue, 14 Feb 2023 12:29:56 +0900 Subject: [PATCH 18/30] Add files via upload --- ...\353\223\234\354\233\214\354\205\234.java" | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 "BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" diff --git "a/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" new file mode 100644 index 0000000..eec8020 --- /dev/null +++ "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" @@ -0,0 +1,76 @@ +package study; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +/** 플로이드 워셜 O(n^3) */ +public class Main_백준_1389_케빈베이컨의6단계법칙_플로이드워셜 { + static int[][] list; + static int[][] bridge; + static int N, M, ans, sum; + static StringBuilder sb = new StringBuilder(); + static int min = Integer.MAX_VALUE; + static int INF = 100; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + list = new int[N + 1][N + 1]; + bridge = new int[N + 1][N + 1]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[a][b] = 1; // 양방향 + list[b][a] = 1; + } + // 배열 초기화 + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + if (i == j) + continue; + else if (list[i][j] == 1) + bridge[i][j] = 1; + else + bridge[i][j] = INF; + } + } + FloydWarshall(); + // 케빈 베이컨의 수가 가장 작은 사람 + for (int i = 1; i <= N; i++) { + sum = 0; + for (int j = 1; j <= N; j++) { + sum += bridge[i][j]; + } + if (min > sum) { + min = sum; + ans = i; + } + } + System.out.println(ans); + } // end of main + + /** 플로이드 워셜 */ + public static void FloydWarshall() { + for (int k = 1; k <= N; k++) { // k : 중간 다리 + for (int i = 1; i <= N; i++) { // i부터 j까지 갈때 중간다리 k를 건널지 말지 (작으면 건넘) + for (int j = 1; j <= N; j++) { + bridge[i][j] = Math.min(bridge[i][j], bridge[i][k] + bridge[k][j]); + } + } + } + } + +} // end of class \ No newline at end of file From 284d4774554f0459225244fbcaa9364bb33bb571 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Sun, 19 Feb 2023 03:55:22 +0900 Subject: [PATCH 19/30] =?UTF-8?q?2=EC=9B=943=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\250\354\206\214\354\227\260_212ms.java" | 67 +++++++++++++++++ ...25\250\354\206\214\354\227\260_260ms.java" | 69 +++++++++++++++++ ...\352\260\204\354\264\210\352\263\274.java" | 70 +++++++++++++++++ ...25\250\354\206\214\354\227\260_924ms.java" | 55 ++++++++++++++ ...25\250\354\206\214\354\227\260_772ms.java" | 75 +++++++++++++++++++ ...25\250\354\206\214\354\227\260_560ms.java" | 43 +++++++++++ 6 files changed, 379 insertions(+) create mode 100644 "\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" create mode 100644 "\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" create mode 100644 "\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" create mode 100644 "\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" create mode 100644 "\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" create mode 100644 "\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" diff --git "a/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" new file mode 100644 index 0000000..b4fd4f3 --- /dev/null +++ "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" @@ -0,0 +1,67 @@ +package 그래프; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_1260_DFS와BFS_실버2_함소연_212ms { + static int[][] arr; + static int N, M, V; + static boolean[] isVisited; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + V = Integer.parseInt(st.nextToken()); + arr = new int[N + 1][N + 1]; + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + arr[a][b] = 1; + arr[b][a] = 1; + } + + isVisited = new boolean[N+1]; + DFS(V); + sb.append("\n"); + Arrays.fill(isVisited, false); + BFS(V); + + System.out.println(sb.toString()); + } + + public static void DFS(int node) { + if(node == arr.length) return; + isVisited[node] = true; + sb.append(node).append(" "); + for (int i = 1; i < arr.length; i++) { + if(!isVisited[i] && arr[node][i] == 1) + DFS(i); + } + } + + public static void BFS(int node) { + Deque queue = new ArrayDeque(); + queue.offer(node); + isVisited[node] = true; + while (!queue.isEmpty()) { + int n = queue.poll(); + sb.append(n).append(" "); + for(int i = 1; i < arr.length; i++) { + if (!isVisited[i] && arr[n][i] == 1) { + queue.offer(i); + isVisited[i] = true; + } + } + } + } +} diff --git "a/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" new file mode 100644 index 0000000..2ea3c0e --- /dev/null +++ "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" @@ -0,0 +1,69 @@ +package 그래프; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_18404_실버1_현명한나이트_함소연_260ms { + static int[][] arr; + static boolean[][] isVisited; + static int[] dx = {-2, -2, -1, -1, 1, 1, 2, 2}; + static int[] dy = {-1, +1, -2, 2, -2, 2, -1, 1}; + static int N, M; + static StringBuilder sb = new StringBuilder(); + static class ChessBoard{ + int x; + int y; + public ChessBoard(int x, int y) { + super(); + this.x = x; + this.y = y; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new int[N+1][N+1]; + isVisited = new boolean[N+1][N+1]; + + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + BFS(x, y); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int kx = Integer.parseInt(st.nextToken()); + int ky = Integer.parseInt(st.nextToken()); + sb.append(arr[kx][ky]).append(" "); + } + + System.out.println(sb.toString()); + } // end of main + + public static void BFS(int x, int y) { + Deque queue = new ArrayDeque(); + queue.offer(new ChessBoard(x, y)); + isVisited[x][y] = true; + while(!queue.isEmpty()) { + ChessBoard board = queue.poll(); + for (int i = 0; i < dx.length; i++) { + int nx = board.x + dx[i]; + int ny = board.y + dy[i]; + if(nx > 0 && nx < N+1 && ny > 0 && ny < N+1 && !isVisited[nx][ny]) { + arr[nx][ny] = arr[board.x][board.y] + 1; + queue.offer(new ChessBoard(nx, ny)); + isVisited[nx][ny] = true; + } + } + } + } // end of BFS +} // end of class diff --git "a/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" new file mode 100644 index 0000000..7bd16f8 --- /dev/null +++ "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" @@ -0,0 +1,70 @@ +package 그래프; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_18404_실버1_현명한나이트_함소연_시간초과 { + static int[][] arr; + static boolean[][] isVisited; + static int[] dx = {-2, -2, -1, -1, 1, 1, 2, 2}; + static int[] dy = {-1, +1, -2, 2, -2, 2, -1, 1}; + static int N, M; + static StringBuilder sb = new StringBuilder(); + static class ChessBoard{ + int x; + int y; + int count; + public ChessBoard(int x, int y, int count) { + super(); + this.x = x; + this.y = y; + this.count = count; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new int[N+1][N+1]; + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + arr[x][y] = 1; + for (int i = 0; i < M; i++) { + isVisited = new boolean[N+1][N+1]; + st = new StringTokenizer(br.readLine()); + int kx = Integer.parseInt(st.nextToken()); + int ky = Integer.parseInt(st.nextToken()); + arr[kx][ky] = -1; + BFS(x, y, 1); + } + System.out.println(sb.toString()); + } // end of main + public static void BFS(int x, int y, int cnt) { + Deque queue = new ArrayDeque(); + queue.add(new ChessBoard(x, y, cnt)); + isVisited[x][y] = true; + while(!queue.isEmpty()) { + ChessBoard board = queue.poll(); + for (int i = 0; i < dx.length; i++) { + int nx = board.x + dx[i]; + int ny = board.y + dy[i]; + if(nx > 0 && nx < N+1 && ny > 0 && ny < N+1 && !isVisited[nx][ny]) { + if(arr[nx][ny] == -1) { + arr[nx][ny] = 0; + sb.append(board.count).append(" "); + return; + } + isVisited[nx][ny] = true; + queue.offer(new ChessBoard(nx, ny, board.count+1)); + } + } + } + } // end of BFS +} // end of class diff --git "a/\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" "b/\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" new file mode 100644 index 0000000..6da817a --- /dev/null +++ "b/\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" @@ -0,0 +1,55 @@ +package 서로소집합; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_1717_집합의표현_골드4_함소연_924ms { + static int[] list; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + list = new int[N + 1]; + for (int i = 0; i < list.length; i++) { + list[i] = i; + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int op = Integer.parseInt(st.nextToken()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + switch (op) { + case 0: // 합집합 + int x = find(a); // 루트 노드 찾디 + int y = find(b); + if (x < y) // 더 작은 루트노드를 부모로 설정 + list[y] = x; + else + list[x] = y; + break; + case 1: // 확인 + if (find(a) == find(b)) // 루트 노드가 같으면 YES + sb.append("YES"); + else + sb.append("NO"); // 다르면 NO + sb.append("\n"); + break; + } + } + System.out.println(sb.toString()); + } // end of main + + public static int find(int i) { + if (i == list[i]) + return i; + return list[i] = find(list[i]); // 경로 압축 + } // end of find +} // end of class diff --git "a/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" new file mode 100644 index 0000000..4eb947a --- /dev/null +++ "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" @@ -0,0 +1,75 @@ +package 위상정렬; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_1005_ACMCraft_골드3_함소연_772ms { + static StringBuilder sb = new StringBuilder(); + static ArrayList[] list; + static int[] delay; + static int[] indegree; + static int N, W; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= T; tc++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); // 건물 개수 + int K = Integer.parseInt(st.nextToken()); // 규칙 수 + + delay = new int[N + 1]; // 건설시간 + indegree = new int[N + 1]; // 인접 차수 + list = new ArrayList[N + 1]; + st = new StringTokenizer(br.readLine(), " "); + for (int i = 1; i <= N; i++) { + delay[i] = Integer.parseInt(st.nextToken()); + list[i] = new ArrayList(); + } + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine(), " "); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[a].add(b); + indegree[b]++; + } + + W = Integer.parseInt(br.readLine()); + + TopologicalSort(); + } + System.out.println(sb.toString()); + } // end of main + + public static void TopologicalSort() { + Deque queue = new ArrayDeque(); + int[] res = new int[N+1]; + for (int i = 1; i <= N; i++) { + if(indegree[i] == 0) { + queue.offer(i); + res[i] = delay[i]; + } + } + while (queue.size() != 0) { + int prev = queue.poll(); + if(prev == W) { // 최종 건물에 도달하면 return + sb.append(res[prev]).append("\n"); + return; + } + for (int now : list[prev]) { + res[now] = Math.max(res[now], res[prev] + delay[now]); + indegree[now]--; + if (indegree[now] == 0) { + queue.offer(now); + } + } + } + } +} // end of class + diff --git "a/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" new file mode 100644 index 0000000..0fd9fc6 --- /dev/null +++ "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" @@ -0,0 +1,43 @@ +package 위상정렬; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; +// 위상정렬 안 쓴 위상정렬 문제 +public class Main_백준_14567_선수과목_골드5_함소연_560ms { + static ArrayList[] list; + static int[] degree; + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); // 과목의 수 + int M = Integer.parseInt(st.nextToken()); // 선수 조건의 수 + + list = new ArrayList[N+1]; + for (int i = 1; i <= N; i++) { + list[i] = new ArrayList(); + } + + degree = new int[N + 1]; // 진입 차수 + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[b].add(a); + } + + for (int i = 1; i <= N; i++) { + for (int b : list[i]) { + degree[i] = Math.max(degree[i], degree[b]+1); // 최대 학기 + } + sb.append(degree[i]+1).append(" "); + } + System.out.println(sb.toString()); + } // end of main +} // end of class From 6188833d54e3a3d27c8471f0365075d9fbe901cd Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 20 Feb 2023 23:03:53 +0900 Subject: [PATCH 20/30] =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\263\204\353\262\225\354\271\231.java" | 77 +++++++++++++++++++ ...\353\223\234\354\233\214\354\205\234.java" | 76 ++++++++++++++++++ ...\353\263\264\353\254\274\354\204\254.java" | 76 ++++++++++++++++++ ...\354\266\234\354\236\221\354\240\204.java" | 52 +++++++++++++ ...\352\263\240\353\245\264\352\270\260.java" | 50 ++++++++++++ ...25\250\354\206\214\354\227\260_212ms.java" | 67 ++++++++++++++++ ...25\250\354\206\214\354\227\260_260ms.java" | 69 +++++++++++++++++ ...\352\260\204\354\264\210\352\263\274.java" | 70 +++++++++++++++++ ...\353\247\236\354\266\224\352\270\260.java" | 34 ++++++++ ...\354\213\244\353\260\260\354\240\225.java" | 40 ++++++++++ ...25\250\354\206\214\354\227\260_280ms.java" | 61 +++++++++++++++ ...225\250\354\206\214\354\227\260_96ms.java" | 52 +++++++++++++ ...5\250\354\206\214\354\227\260_6040ms.java" | 40 ++++++++++ ...00_17829_222\355\222\200\353\247\201.java" | 52 +++++++++++++ ...\353\223\234\355\212\270\353\246\254.java" | 54 +++++++++++++ ...25\250\354\206\214\354\227\260_924ms.java" | 55 +++++++++++++ ...\355\203\235\354\210\230\354\227\264.java" | 40 ++++++++++ ...\355\202\244\353\241\234\352\261\260.java" | 56 ++++++++++++++ ...\354\227\220\353\224\224\355\204\260.java" | 49 ++++++++++++ ...\353\217\204\352\263\265\354\202\254.java" | 68 ++++++++++++++++ .../BOJ_1120.java" | 36 +++++++++ .../BOJ_18111.java" | 66 ++++++++++++++++ .../BOJ_2503.java" | 76 ++++++++++++++++++ .../BOJ_2615.java" | 75 ++++++++++++++++++ ...25\250\354\206\214\354\227\260_772ms.java" | 75 ++++++++++++++++++ ...25\250\354\206\214\354\227\260_560ms.java" | 43 +++++++++++ .../BOJ_13335_\355\212\270\353\237\255.java" | 49 ++++++++++++ ...\354\225\265\353\254\264\354\203\210.java" | 57 ++++++++++++++ .../BOJ_1068_\355\212\270\353\246\254.java" | 69 +++++++++++++++++ ...\353\246\254\354\210\234\355\232\214.java" | 64 +++++++++++++++ 30 files changed, 1748 insertions(+) create mode 100644 "BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" create mode 100644 "BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" create mode 100644 "BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" create mode 100644 "DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" create mode 100644 "DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" create mode 100644 "\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" create mode 100644 "\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" create mode 100644 "\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" create mode 100644 "\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" create mode 100644 "\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" create mode 100644 "\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_280ms.java" create mode 100644 "\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_10971_\354\231\270\355\214\220\354\233\220\354\210\234\355\232\2142_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_96ms.java" create mode 100644 "\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_9663_NQUEEN_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_6040ms.java" create mode 100644 "\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" create mode 100644 "\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" create mode 100644 "\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" create mode 100644 "\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" create mode 100644 "\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" create mode 100644 "\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" create mode 100644 "\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" create mode 100644 "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" create mode 100644 "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" create mode 100644 "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" create mode 100644 "\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" create mode 100644 "\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" create mode 100644 "\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" create mode 100644 "\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" create mode 100644 "\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" create mode 100644 "\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" create mode 100644 "\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" diff --git "a/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" new file mode 100644 index 0000000..6b1f78f --- /dev/null +++ "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231.java" @@ -0,0 +1,77 @@ +package BFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +/** BFS */ +public class Main_백준_1389_케빈베이컨의6단계법칙 { + static int[][] list; + static boolean[] isVisited; + static int N, M, ans; + static StringBuilder sb = new StringBuilder(); + static int min = Integer.MAX_VALUE; + static class Friend{ + int node; // 탐색 시작 노드 + int count; // 친구 수 + public Friend(int node, int count) { + this.node = node; + this.count = count; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + list = new int[N+1][N+1]; + isVisited = new boolean[N+1]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[a][b] = 1; // 양방향 + list[b][a] = 1; + } + + //모든 노드에서 시작 + for (int i = 1; i <= N; i++) { + Arrays.fill(isVisited, false); + BFS(i); + } + System.out.println(ans); + } // end of main + + public static void BFS(int node) { + Queue queue = new ArrayDeque(); + queue.offer(new Friend(node, 0)); // 큐에 삽입 + isVisited[node] = true; // 방문 + int cnt = 0; // + while(!queue.isEmpty()) { + Friend friend = queue.poll(); // 맨 앞의 값 꺼내기 + cnt += friend.count; + + for (int i = 1; i <= N; i++) { + // list[node][ ] 전체 탐색 && 방문하지 않음 + if(list[friend.node][i] == 1&& !isVisited[i] ) { + isVisited[i] = true; + queue.offer(new Friend(i, friend.count + 1)); // 가중치 + 1 + } + } + } // end of while + if(min > cnt) { + min = cnt; + ans = node; + } + } // end of BFS +} // end of class diff --git "a/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" new file mode 100644 index 0000000..791a560 --- /dev/null +++ "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" @@ -0,0 +1,76 @@ + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +/** 플로이드 워셜 O(n^3) */ +public class Main_백준_1389_케빈베이컨의6단계법칙_플로이드워셜 { + static int[][] list; + static int[][] bridge; + static int N, M, ans, sum; + static StringBuilder sb = new StringBuilder(); + static int min = Integer.MAX_VALUE; + static int INF = 100; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + list = new int[N + 1][N + 1]; + bridge = new int[N + 1][N + 1]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[a][b] = 1; // 양방향 + list[b][a] = 1; + } + // 배열 초기화 + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + if (i == j) + continue; + else if (list[i][j] == 1) + bridge[i][j] = 1; + else + bridge[i][j] = INF; + } + } + FloydWarshall(); + // 케빈 베이컨의 수가 가장 작은 사람 + for (int i = 1; i <= N; i++) { + sum = 0; + for (int j = 1; j <= N; j++) { + sum += bridge[i][j]; + } + if (min > sum) { + min = sum; + ans = i; + } + } + System.out.println(ans); + } // end of main + + /** 플로이드 워셜 */ + public static void FloydWarshall() { + for (int k = 1; k <= N; k++) { // k : 중간 다리 + for (int i = 1; i <= N; i++) { // i부터 j까지 갈때 중간다리 k를 건널지 말지 (작으면 건넘) + for (int j = 1; j <= N; j++) { + bridge[i][j] = Math.min(bridge[i][j], bridge[i][k] + bridge[k][j]); + } + } + } + } + +} // end of class \ No newline at end of file diff --git "a/BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" "b/BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" new file mode 100644 index 0000000..56841a9 --- /dev/null +++ "b/BFS/Main_\353\260\261\354\244\200_2589_\353\263\264\353\254\274\354\204\254.java" @@ -0,0 +1,76 @@ +package BFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; +import java.util.StringTokenizer; + +/** BFS */ +public class Main_백준_2589_보물섬 { + static int N, M, maxCnt; + static char[][] map; + static boolean[][] isVisited; + static int[] dx = {-1, 0, 1, 0}; + static int[] dy = {0, -1, 0, 1}; + + static class treasureMap{ + int x; + int y; + int count; + public treasureMap(int x, int y, int count) { + this.x = x; + this.y = y; + this.count = count; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + map = new char[N][M]; + for (int i = 0; i < N; i++) { + String s = br.readLine(); + for (int j = 0; j < M; j++) { + map[i][j] = s.charAt(j); + } + } + + // 지도 탐색 + int ans = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if(map[i][j] == 'L') { // 육지일 때만 탐색 + isVisited = new boolean[N][M]; + BFS(i, j); + ans = Math.max(ans, maxCnt); // 최대값과 비교 + } + } + } + System.out.println(ans); + } // end of main + + static void BFS(int posX, int posY) { + Queue queue = new ArrayDeque(); + queue.offer(new treasureMap(posX, posY, 0)); + isVisited[posX][posY] = true; + maxCnt = 0; + while(!queue.isEmpty()) { + treasureMap t = queue.poll(); + for (int i = 0; i < 4; i++) { + int nowX = t.x + dx[i]; + int nowY = t.y + dy[i]; + // 범위 내의 이동 && 방문하지 않음 && 육지 + if(nowX >= 0 && nowX < N && nowY >= 0 && nowY < M && !isVisited[nowX][nowY] && map[nowX][nowY] == 'L') { + isVisited[nowX][nowY] = true; + queue.offer(new treasureMap(nowX, nowY, t.count + 1)); // 가중치 + 1 + maxCnt = Math.max(maxCnt, t.count + 1); // 해당 시작점에서 가장 먼 곳 찾기 + } + } + } // end of while + } // end of BFS +} // end of class diff --git "a/DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" "b/DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" new file mode 100644 index 0000000..1509288 --- /dev/null +++ "b/DFS/Main_\353\260\261\354\244\200_16437_\354\226\221\352\265\254\354\266\234\354\236\221\354\240\204.java" @@ -0,0 +1,52 @@ +package DFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** 후위 순회 트리 */ +public class Main_백준_16437_양구출작전 { + static int N; + static ArrayList Island[]; // 트리 저장 + static long[] animalCnt; // 동물 수 저장 + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + Island = new ArrayList[N+1]; + animalCnt = new long[N+1]; + for (int i = 1; i <= N; i++) { + Island[i] = new ArrayList(); + } + + for (int i = 2; i <= N; i++) { + st = new StringTokenizer(br.readLine(), " "); + char animal = st.nextToken().charAt(0); + int count = Integer.parseInt(st.nextToken()); + if(animal == 'W') { // 늑대 수는 음수 + count *= -1; + } + animalCnt[i] = count; + int bridge = Integer.parseInt(st.nextToken()); + Island[bridge].add(i); + } + + DFS(1, 0); + System.out.println(animalCnt[1]); + } // end of main + + public static void DFS(int now, int prev) { + for (int next : Island[now]) { + DFS(next, now); + } + if(prev == 0) { // 루트노드면 종료 + return; + } + if(animalCnt[now] > 0) // 양이면 부모 노드에 sum + animalCnt[prev] += animalCnt[now]; + } +} // end of class diff --git "a/DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" "b/DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" new file mode 100644 index 0000000..aed412a --- /dev/null +++ "b/DFS/Main_\353\260\261\354\244\200_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.java" @@ -0,0 +1,50 @@ +package DFS; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class Main_백준_2668_숫자고르기 { + static int[] arr; + static boolean[] isVisited; + static ArrayList list = new ArrayList(); + static int N; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + N = Integer.parseInt(br.readLine()); + arr = new int[N+1]; + for (int i = 1; i <= N; i++) { + arr[i] = Integer.parseInt(br.readLine()); + } + isVisited = new boolean[N+1]; + for (int i = 1; i <= N; i++) { + Arrays.fill(isVisited, false); + DFS(i, i); + } + Collections.sort(list); + sb.append(list.size()).append("\n"); + for (Integer i : list) { + sb.append(i).append("\n"); + } + System.out.println(sb.toString()); + } // end of main + + public static void DFS(int node, int target) { + // 사이클이 같을 때 추가하고 종료 + if(arr[node] == target) { + list.add(node); + return; + } + // 사이클 X + if(isVisited[node]) { + return; + } + // 사이클 재귀 + isVisited[node] = true; + DFS(arr[node], target); + } // end of DFS +} // end of class diff --git "a/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" new file mode 100644 index 0000000..b4fd4f3 --- /dev/null +++ "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_1260_DFS\354\231\200BFS_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_212ms.java" @@ -0,0 +1,67 @@ +package 그래프; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_1260_DFS와BFS_실버2_함소연_212ms { + static int[][] arr; + static int N, M, V; + static boolean[] isVisited; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + V = Integer.parseInt(st.nextToken()); + arr = new int[N + 1][N + 1]; + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + arr[a][b] = 1; + arr[b][a] = 1; + } + + isVisited = new boolean[N+1]; + DFS(V); + sb.append("\n"); + Arrays.fill(isVisited, false); + BFS(V); + + System.out.println(sb.toString()); + } + + public static void DFS(int node) { + if(node == arr.length) return; + isVisited[node] = true; + sb.append(node).append(" "); + for (int i = 1; i < arr.length; i++) { + if(!isVisited[i] && arr[node][i] == 1) + DFS(i); + } + } + + public static void BFS(int node) { + Deque queue = new ArrayDeque(); + queue.offer(node); + isVisited[node] = true; + while (!queue.isEmpty()) { + int n = queue.poll(); + sb.append(n).append(" "); + for(int i = 1; i < arr.length; i++) { + if (!isVisited[i] && arr[n][i] == 1) { + queue.offer(i); + isVisited[i] = true; + } + } + } + } +} diff --git "a/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" new file mode 100644 index 0000000..2ea3c0e --- /dev/null +++ "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_260ms.java" @@ -0,0 +1,69 @@ +package 그래프; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_18404_실버1_현명한나이트_함소연_260ms { + static int[][] arr; + static boolean[][] isVisited; + static int[] dx = {-2, -2, -1, -1, 1, 1, 2, 2}; + static int[] dy = {-1, +1, -2, 2, -2, 2, -1, 1}; + static int N, M; + static StringBuilder sb = new StringBuilder(); + static class ChessBoard{ + int x; + int y; + public ChessBoard(int x, int y) { + super(); + this.x = x; + this.y = y; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new int[N+1][N+1]; + isVisited = new boolean[N+1][N+1]; + + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + BFS(x, y); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int kx = Integer.parseInt(st.nextToken()); + int ky = Integer.parseInt(st.nextToken()); + sb.append(arr[kx][ky]).append(" "); + } + + System.out.println(sb.toString()); + } // end of main + + public static void BFS(int x, int y) { + Deque queue = new ArrayDeque(); + queue.offer(new ChessBoard(x, y)); + isVisited[x][y] = true; + while(!queue.isEmpty()) { + ChessBoard board = queue.poll(); + for (int i = 0; i < dx.length; i++) { + int nx = board.x + dx[i]; + int ny = board.y + dy[i]; + if(nx > 0 && nx < N+1 && ny > 0 && ny < N+1 && !isVisited[nx][ny]) { + arr[nx][ny] = arr[board.x][board.y] + 1; + queue.offer(new ChessBoard(nx, ny)); + isVisited[nx][ny] = true; + } + } + } + } // end of BFS +} // end of class diff --git "a/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" new file mode 100644 index 0000000..7bd16f8 --- /dev/null +++ "b/\352\267\270\353\236\230\355\224\204/Main_\353\260\261\354\244\200_18404_\354\213\244\353\262\2041_\355\230\204\353\252\205\355\225\234\353\202\230\354\235\264\355\212\270_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" @@ -0,0 +1,70 @@ +package 그래프; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_18404_실버1_현명한나이트_함소연_시간초과 { + static int[][] arr; + static boolean[][] isVisited; + static int[] dx = {-2, -2, -1, -1, 1, 1, 2, 2}; + static int[] dy = {-1, +1, -2, 2, -2, 2, -1, 1}; + static int N, M; + static StringBuilder sb = new StringBuilder(); + static class ChessBoard{ + int x; + int y; + int count; + public ChessBoard(int x, int y, int count) { + super(); + this.x = x; + this.y = y; + this.count = count; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new int[N+1][N+1]; + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + arr[x][y] = 1; + for (int i = 0; i < M; i++) { + isVisited = new boolean[N+1][N+1]; + st = new StringTokenizer(br.readLine()); + int kx = Integer.parseInt(st.nextToken()); + int ky = Integer.parseInt(st.nextToken()); + arr[kx][ky] = -1; + BFS(x, y, 1); + } + System.out.println(sb.toString()); + } // end of main + public static void BFS(int x, int y, int cnt) { + Deque queue = new ArrayDeque(); + queue.add(new ChessBoard(x, y, cnt)); + isVisited[x][y] = true; + while(!queue.isEmpty()) { + ChessBoard board = queue.poll(); + for (int i = 0; i < dx.length; i++) { + int nx = board.x + dx[i]; + int ny = board.y + dy[i]; + if(nx > 0 && nx < N+1 && ny > 0 && ny < N+1 && !isVisited[nx][ny]) { + if(arr[nx][ny] == -1) { + arr[nx][ny] = 0; + sb.append(board.count).append(" "); + return; + } + isVisited[nx][ny] = true; + queue.offer(new ChessBoard(nx, ny, board.count+1)); + } + } + } + } // end of BFS +} // end of class diff --git "a/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" new file mode 100644 index 0000000..79faa2f --- /dev/null +++ "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_11509_\355\222\215\354\204\240\353\247\236\354\266\224\352\270\260.java" @@ -0,0 +1,34 @@ +package 그리디; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_11509_풍선맞추기 { + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + int[] balloon = new int[N+1]; + int[] arrow = new int[1000001]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + balloon[i] = Integer.parseInt(st.nextToken()); + } + int cnt = 0; + int height = 0; + for (int i = 1; i <= N; i++) { + height = balloon[i]; + // 맞춘 적이 없다면 + if(arrow[height] == 0) { + arrow[height-1]++; // 다음에 와야할 풍선 높이에 check + cnt++; // 화살++ + }else { // 맞춘 적이 있다면 + arrow[height]--; // 맞춰서 check 풀기 + arrow[height-1]++; // 다음에 와야할 풍선 높이에 check + } + } + System.out.println(cnt); + } +} diff --git "a/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" new file mode 100644 index 0000000..93f9e06 --- /dev/null +++ "b/\352\267\270\353\246\254\353\224\224/Main_\353\260\261\354\244\200_1931_\355\232\214\354\235\230\354\213\244\353\260\260\354\240\225.java" @@ -0,0 +1,40 @@ +package 그리디; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; +import java.util.StringTokenizer; + +public class Main_백준_1931_회의실배정 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int N = Integer.parseInt(br.readLine()); // 회의 수 + int[][] arr = new int[N][2]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + arr[i][0] = Integer.parseInt(st.nextToken()); // 시작 시간 + arr[i][1] = Integer.parseInt(st.nextToken()); // 종료 시간 + } + + // 회의 종료 시간이 빠른 것부터 정렬 + Arrays.sort(arr, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if(o1[1] == o2[1]) return o1[0] - o2[0]; // 종료시간이 같으면 시작시간 정렬 + return o1[1] - o2[1]; // 오름차순 + } + }); + int ans = 0; + int time = 0; + for (int i = 0; i < N; i++) { + if(time <= arr[i][0]) { // 끝나는 시간과 같거나 큰 다음 시작 시간이 있다면, + time = arr[i][1]; + ans++; + } + } + System.out.println(ans); + } +} diff --git "a/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_280ms.java" "b/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_280ms.java" new file mode 100644 index 0000000..2115dcb --- /dev/null +++ "b/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_280ms.java" @@ -0,0 +1,61 @@ +package 백트래킹; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_1062_가르침_골드4_함소연_280ms { + static boolean[] isVisited; + static char[][] word; + static int N, K, max; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + isVisited = new boolean[26]; // 'a' = 97 + word = new char[N][15]; + isVisited[0] = true; isVisited['n'-'a'] = true; isVisited['t'-'a'] = true; isVisited['i'-'a'] = true; isVisited['c'-'a'] = true; + + if(K < 5) { + System.out.println(0); + return; + } + for (int k = 0; k < N; k++) { + char[] ch = br.readLine().toCharArray(); + word[k] = ch; + } + find(0, 0); + System.out.println(max); + } + public static void find(int idx, int cnt) { + if(cnt == K - 5) { + int temp = 0; + for (int i = 0; i < N; i++) { + boolean flag = true; + for (int j = 0; j < word[i].length; j++) { + int cur = word[i][j] -'a'; + if(!isVisited[cur]) { + flag = false; + break; + } + } + if(flag) { + temp++; + } + } + max = Math.max(temp, max); + return; + } + for (int i = idx; i < 26; i++) { + if(!isVisited[i]) { + isVisited[i] = true; + find(i, cnt+1); + isVisited[i] =false; + } + } + } + +} diff --git "a/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_10971_\354\231\270\355\214\220\354\233\220\354\210\234\355\232\2142_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_96ms.java" "b/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_10971_\354\231\270\355\214\220\354\233\220\354\210\234\355\232\2142_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_96ms.java" new file mode 100644 index 0000000..1668322 --- /dev/null +++ "b/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_10971_\354\231\270\355\214\220\354\233\220\354\210\234\355\232\2142_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_96ms.java" @@ -0,0 +1,52 @@ +package 백트래킹; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_10971_외판원순회2_실버2_함소연_96ms { + static int[][] arr; + static int N, from, min = Integer.MAX_VALUE; + static boolean[] isVisited; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); // 도시의 수 + arr = new int[N][N]; // 비용 행렬 + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + for (int i = 0; i < N; i++) { + isVisited = new boolean[N]; + from = i; + DFS(i, 1, 0); + } + + System.out.println(min); + } + public static void DFS(int start, int cnt, int sum) { // start : 현재 도시, cnt : 이동 횟수, sum : 이동 비용 합 + if (cnt == N) { // 마지막 목적지까지 가면 다시 되돌아옴. + if(arr[start][from] == 0) return; // 갈 수 없으면 return + sum += arr[start][from]; + min = Math.min(sum, min); + return; + } else { + isVisited[start] = true; + for (int i = 0; i < N; i++) { + if (!isVisited[i] && arr[start][i] != 0) { + isVisited[i] = true; + sum += arr[start][i]; + if(sum <= min) { // 최소 비용보다 크면 이동하지 X + DFS(i, cnt + 1, sum); + } + sum -= arr[start][i]; + isVisited[i] = false; + } + } + } + } +} diff --git "a/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_9663_NQUEEN_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_6040ms.java" "b/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_9663_NQUEEN_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_6040ms.java" new file mode 100644 index 0000000..83a2cdd --- /dev/null +++ "b/\353\260\261\355\212\270\353\236\230\355\202\271/Main_\353\260\261\354\244\200_9663_NQUEEN_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_6040ms.java" @@ -0,0 +1,40 @@ +package 백트래킹; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Main_백준_9663_NQUEEN_골드4_함소연_6040ms { + static int N, res = 0; + static int[] board; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + board = new int[N]; + Queen(0); + System.out.println(res); + } // end of main + + public static void Queen(int n) { + if (n == N) { + res++; + return; + } + for (int i = 0; i < board.length; i++) { + board[n] = i; + if (promising(n)) { + Queen(n + 1); + } + } + } // end of queen + + public static boolean promising(int n) { + for (int i = 0; i < n; i++) { + // 대각선 (행의 차 == 열의 차)일 경우, 행과 열이 같을 경우 + if(Math.abs(n - i) == Math.abs(board[n] - board[i])|| board[n] == board[i]) return false; + } + return true; + } // end of promising +} // end of class diff --git "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" new file mode 100644 index 0000000..4137b75 --- /dev/null +++ "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" @@ -0,0 +1,52 @@ +package 분할정복; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_17829_222풀링 { + static int[][] pool; + static int N; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + pool = new int[N][N]; + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + pool[i][j] = Integer.parseInt(st.nextToken()); + } + } + System.out.println(Pooling(N, 0, 0)); + } // end of main + + public static int Pooling(int N, int x, int y) { + if(N == 2) { + return FindSecond(N, x, y); + }else { + int[] arr = new int[4]; + int N2 = N/2; + arr[0] = Pooling(N2, x, y); + arr[1] = Pooling(N2, x + N2, y); + arr[2] = Pooling(N2, x, y + N2); + arr[3] = Pooling(N2, x + N2, y + N2); + Arrays.sort(arr); + return arr[2]; // 두 번째로 큰 수 + } + } // end of Pooling + + public static int FindSecond(int N, int x, int y) { + int[] arr = new int[4]; + int idx = 0; + for (int i = x; i < x + 2; i++) { + for (int j = y; j < y + 2; j++) { + arr[idx++] = pool[i][j]; + } + } + Arrays.sort(arr); + return arr[2]; // 두 번째로 큰 수 + } // end of FindSecond +} // end of class \ No newline at end of file diff --git "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" new file mode 100644 index 0000000..344366e --- /dev/null +++ "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" @@ -0,0 +1,54 @@ +package 분할정복; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_1992_쿼드트리 { + static int[][] arr; + static int N; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + arr = new int[N][N]; + for (int i = 0; i < N; i++) { + String str = br.readLine(); + for (int j = 0; j < N; j++) { + arr[i][j] = str.charAt(j) - '0'; + } + } + QuadTree(N, 0, 0); + System.out.println(sb.toString()); + } // end of main + + public static void QuadTree(int N, int x, int y) { + if(N < 1) return; // 더이상 쪼갤 수 없으면 return + if(check(N, x, y)) { // 모두 1이거나 0이면 만족 + if(arr[x][y] == 1) { + sb.append(1); + }else + sb.append(0); + }else { + sb.append("("); + int N2 = N/2; + QuadTree(N2, x, y); // (0, 0) + QuadTree(N2, x, y + N2); // (0, 1) + QuadTree(N2, x + N2, y); // (1, 0) + QuadTree(N2, x + N2, y + N2); // (1, 1) + sb.append(")"); + } + + } // end of QuadTree + public static boolean check(int N, int x, int y) { + int color = arr[x][y]; // 맨 처음 색상 + for (int i = x; i < x+N ; i++) { + for (int j = y; j < y+N; j++) { + if(arr[i][j] != color) + return false; + } + } + return true; + } // end of check +} // end of class diff --git "a/\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" "b/\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" new file mode 100644 index 0000000..6da817a --- /dev/null +++ "b/\354\204\234\353\241\234\354\206\214\354\247\221\355\225\251/Main_\353\260\261\354\244\200_1717_\354\247\221\355\225\251\354\235\230\355\221\234\355\230\204_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_924ms.java" @@ -0,0 +1,55 @@ +package 서로소집합; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_1717_집합의표현_골드4_함소연_924ms { + static int[] list; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + list = new int[N + 1]; + for (int i = 0; i < list.length; i++) { + list[i] = i; + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int op = Integer.parseInt(st.nextToken()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + switch (op) { + case 0: // 합집합 + int x = find(a); // 루트 노드 찾디 + int y = find(b); + if (x < y) // 더 작은 루트노드를 부모로 설정 + list[y] = x; + else + list[x] = y; + break; + case 1: // 확인 + if (find(a) == find(b)) // 루트 노드가 같으면 YES + sb.append("YES"); + else + sb.append("NO"); // 다르면 NO + sb.append("\n"); + break; + } + } + System.out.println(sb.toString()); + } // end of main + + public static int find(int i) { + if (i == list[i]) + return i; + return list[i] = find(list[i]); // 경로 압축 + } // end of find +} // end of class diff --git "a/\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" "b/\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" new file mode 100644 index 0000000..2c588af --- /dev/null +++ "b/\354\212\244\355\203\235/BOJ_1874_\354\212\244\355\203\235\354\210\230\354\227\264.java" @@ -0,0 +1,40 @@ +package 스택; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +/** + * + * stack : + * 1. 현재 수열 값 >= 자연수 : push + * 2. 현재 수열 값 < 자연수 : pop + */ +public class BOJ_1874_스택수열 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + Stack stack = new Stack(); + int N = Integer.parseInt(br.readLine()); + int index = 1; // 자연수 + for (int i = 0; i < N; i++) { + int num = Integer.parseInt(br.readLine()); // 현재 수열 값 +// * 1. 현재 수열 값 >= 자연수 : push + if (num >= index) { + while (num >= index) { + stack.push(index++); + sb.append("+\n"); + } + } +// * 2. 현재 수열 값 < 자연수 : pop + else if (stack.peek() > num) { // 스택 맨 위의 수보다 큰 자연수는 찾을 수가 없음. + System.out.println("NO"); + return; + } + stack.pop(); + sb.append("-\n"); + } + System.out.println(sb); + } +} \ No newline at end of file diff --git "a/\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" "b/\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" new file mode 100644 index 0000000..a618301 --- /dev/null +++ "b/\354\212\244\355\203\235/BOJ_5397_\355\202\244\353\241\234\352\261\260.java" @@ -0,0 +1,56 @@ +package 스택 +; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; +/** + * + * 커서를 가운데에 놓고 좌우 stack 이동 + * + */ +public class BOJ_5397_키로거 { + char left = '<'; + char right = '>'; + char back = '-'; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + int T = Integer.parseInt(br.readLine()); + + for (int tc = 0; tc < T; tc++) { + Stack left = new Stack(); + Stack right = new Stack(); + String s = br.readLine(); + String[] input = s.split(""); + for (int i = 0; i < input.length; i++) { + switch (input[i]) { + case "<": + if(!left.isEmpty()) + right.push(left.pop()); + break; + case ">": + if(!right.isEmpty()) + left.push(right.pop()); + break; + case "-": + if(!left.isEmpty()) + left.pop(); + break; + default: + left.push(input[i]); + } + } + + while(!left.isEmpty()) { + right.push(left.pop()); + } + while(!right.isEmpty()) { + sb.append(right.pop()); + } + sb.append("\n"); + } + System.out.println(sb); + } +} diff --git "a/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" new file mode 100644 index 0000000..625de16 --- /dev/null +++ "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_1406_\354\227\220\353\224\224\355\204\260.java" @@ -0,0 +1,49 @@ +package 연결리스트; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +public class BOJ_1406_에디터 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + Stack left = new Stack(); + Stack right = new Stack(); + String s = br.readLine(); + String[] srr = s.split(""); + for (int i = 0; i < s.length(); i++) { + left.add(srr[i]); + } + int M = Integer.parseInt(br.readLine()); + for (int i = 0; i < M; i++) { + String[] input = br.readLine().split(" "); + switch (input[0]) { + case "L": + if(!left.isEmpty()) + right.push(left.pop()); + break; + case "D": + if(!right.isEmpty()) + left.push(right.pop()); + break; + case "B": + if(!left.isEmpty()) + left.pop(); + break; + default: + left.push(input[1]); + break; + } + } + + while(!left.isEmpty()) { + right.push(left.pop()); + } + while(!right.isEmpty()) { + sb.append(right.pop()); + } + System.out.println(sb); + } +} diff --git "a/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" new file mode 100644 index 0000000..38d3c35 --- /dev/null +++ "b/\354\227\260\352\262\260\353\246\254\354\212\244\355\212\270/BOJ_23309_\354\262\240\353\217\204\352\263\265\354\202\254.java" @@ -0,0 +1,68 @@ +package 연결리스트; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.StringTokenizer; + +public class BOJ_23309_철도공사 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + LinkedList list = new LinkedList(); + int N = Integer.parseInt(st.nextToken()); // 역의 개수 + int M = Integer.parseInt(st.nextToken()); // 공사 횟수 + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + list.add(i, Integer.parseInt(st.nextToken())); + } + + int idx; + int jdx; + int change; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine(), " "); + String key = st.nextToken(); + switch (key) { + case "BN": + idx = Integer.parseInt(st.nextToken()); + jdx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)+1; + + if(change >= list.size()) {change = 0;} + sb.append(list.get(change)+"\n"); + list.add(change, jdx); + break; + case "BP": + idx = Integer.parseInt(st.nextToken()); + jdx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)-1; + if(change < 0) {change = list.size() - 1;} + sb.append(list.get(change)+"\n"); + list.add(change+1, jdx); + break; + case "CN": + idx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)+1; + if(change >= list.size()) {change = 0;} + sb.append(list.get(change)+"\n"); + list.remove(change); + break; + case "CP": + idx = Integer.parseInt(st.nextToken()); + change = list.indexOf(idx)-1; + if(change < 0) {change = list.size() - 1;} + sb.append(list.get(change)+"\n"); + list.remove(change); + break; + default: + break; + } + } + System.out.println(sb); // 시간초과;; + } +} diff --git "a/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" new file mode 100644 index 0000000..3011130 --- /dev/null +++ "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_1120.java" @@ -0,0 +1,36 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * + * 문자열 : + * + */ +public class BOJ_1120 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + String A = st.nextToken(); + String B = st.nextToken(); + + + int min = Integer.MAX_VALUE; + for (int i = 0; i <= B.length()-A.length(); i++) { + int not = 0; + for (int j = 0; j < A.length(); j++) { + if(A.charAt(j) != B.charAt(i+j)) { + not++; + } + if(not > min) break; + } + if(not < min) min = not; + } + System.out.println(min); + } +} diff --git "a/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" new file mode 100644 index 0000000..b1b5afb --- /dev/null +++ "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_18111.java" @@ -0,0 +1,66 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BOJ_18111 { + static int[][] map; + static int N; + static int M; + static int B; + static int time; + static int Block; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + B = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + int min = Integer.MAX_VALUE; + int h = 0; + for (int i = 0; i < 257; i++) { + time = 0; + Block = B; + for (int j = 0; j < N; j++) { + for (int k = 0; k < M; k++) { + if (map[j][k] == i) + continue; + else if (map[j][k] > i) { + minus(j, k, i); + } else { + plus(j, k, i); + } + } + } + + if (min >= time && Block >= 0) { + min = time; + h = i; + } + } + System.out.print(min + " " + h); + } + + public static void plus(int j, int k, int i) { + Block -= i - map[j][k]; + time += 1 * (i - map[j][k]); + } + + public static void minus(int j, int k, int i) { + Block += map[j][k] - i; + time += 2 * (map[j][k] - i); + } +} diff --git "a/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" new file mode 100644 index 0000000..bbb74f3 --- /dev/null +++ "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2503.java" @@ -0,0 +1,76 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BOJ_2503 { + static int[] arr; + static int[] strike; + static int[] ball; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + arr = new int [N]; + strike = new int [N]; + ball = new int [N]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + arr[i] = Integer.parseInt(st.nextToken()); + strike[i] = Integer.parseInt(st.nextToken()); + ball[i] = Integer.parseInt(st.nextToken()); + } + int result = 0; + for (int i = 123; i <= 987; i++) { + boolean flag = false; + + + int h = i/100; + int t = i/10%10; + int u = i%10; + + // 같은 수가 나올 경우 || 0이 나올 경우 continue + if(h == t || h == u || t == u || t == 0 || u == 0) { + continue; + } + + for (int j = 0; j < N; j++) { + int checkH = arr[j]/100; + int checkT = arr[j]/10%10; + int checkU = arr[j]%10; + int cntS = 0; + int cntB = 0; + + // strike + if(h == checkH) cntS++; + if(t == checkT) cntS++; + if(u == checkU) cntS++; + + // ball + if(h == checkT || h == checkU) cntB++; + if(t == checkH || t == checkU) cntB++; + if(u == checkH || u == checkT) cntB++; + + // ball과 strike 횟수가 같으면 true 아니면 false + if(ball[j] != cntB || strike[j] != cntS) { + flag = false; + break; + }else { + flag = true; + } + } + // N번 다 true일 경우 가능성있는 답 개수++ + if(flag) { + + result++; + } + } + + System.out.println(result); + } +} diff --git "a/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" new file mode 100644 index 0000000..b5bea6f --- /dev/null +++ "b/\354\231\204\354\240\204\355\203\220\354\203\211/BOJ_2615.java" @@ -0,0 +1,75 @@ +package 완전탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BOJ_2615 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int[][] arr = new int[19][19]; + int[] dx = { 1, 0, 1, 1 }; // 오른쪽, 아래, 좌측 대각선, 우측 대각선 + int[] dy = { 0, 1, -1, 1 }; + + for (int i = 0; i < arr.length; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < arr.length; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr.length; j++) { + // 1또는 2일때 연속되는 지 검사 + if (arr[i][j] == 1 || arr[i][j] == 2) { + // 가로 세로 대각선 검사 + for (int k = 0; k < 4; k++) { + int cnt = 1; + int nx = i + dx[k]; + int ny = j + dy[k]; + int prev = arr[i][j]; + if (nx >= 19 || nx < 0 || ny >= 19 || ny < 0) + continue; + // 5칸 검사 + while (arr[nx][ny] == prev) { + cnt++; + nx += dx[k]; + ny += dy[k]; + if (cnt > 5) + break; + if (nx >= 19 || nx < 0 || ny >= 19 || ny < 0) + break; + } + + // 6개이면 break + int px = i - dx[k]; + int py = j - dy[k]; + if (px >= 0 && px < 19 && py >= 0 && py < 19 && arr[px][py] == prev) { + continue; + } + + // 5칸 연속이라면, + if (cnt == 5) { + // 승리자 출력 + System.out.println(prev); + + // 가장 왼쪽에 있는 오목 출력 + if (j > ny - dy[k]) + System.out.println((nx - dx[k] + 1) + " " + (ny - dy[k]+ 1)); + else + System.out.println((i + 1) + " " + (j + 1)); + + return; + } + + } + } + } + } + System.out.println(0); + // 6개인지 검사 + } +} diff --git "a/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" new file mode 100644 index 0000000..4eb947a --- /dev/null +++ "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1005_ACMCraft_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_772ms.java" @@ -0,0 +1,75 @@ +package 위상정렬; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_1005_ACMCraft_골드3_함소연_772ms { + static StringBuilder sb = new StringBuilder(); + static ArrayList[] list; + static int[] delay; + static int[] indegree; + static int N, W; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= T; tc++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); // 건물 개수 + int K = Integer.parseInt(st.nextToken()); // 규칙 수 + + delay = new int[N + 1]; // 건설시간 + indegree = new int[N + 1]; // 인접 차수 + list = new ArrayList[N + 1]; + st = new StringTokenizer(br.readLine(), " "); + for (int i = 1; i <= N; i++) { + delay[i] = Integer.parseInt(st.nextToken()); + list[i] = new ArrayList(); + } + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine(), " "); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[a].add(b); + indegree[b]++; + } + + W = Integer.parseInt(br.readLine()); + + TopologicalSort(); + } + System.out.println(sb.toString()); + } // end of main + + public static void TopologicalSort() { + Deque queue = new ArrayDeque(); + int[] res = new int[N+1]; + for (int i = 1; i <= N; i++) { + if(indegree[i] == 0) { + queue.offer(i); + res[i] = delay[i]; + } + } + while (queue.size() != 0) { + int prev = queue.poll(); + if(prev == W) { // 최종 건물에 도달하면 return + sb.append(res[prev]).append("\n"); + return; + } + for (int now : list[prev]) { + res[now] = Math.max(res[now], res[prev] + delay[now]); + indegree[now]--; + if (indegree[now] == 0) { + queue.offer(now); + } + } + } + } +} // end of class + diff --git "a/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" new file mode 100644 index 0000000..0fd9fc6 --- /dev/null +++ "b/\354\234\204\354\203\201\354\240\225\353\240\254/Main_\353\260\261\354\244\200_14567_\354\204\240\354\210\230\352\263\274\353\252\251_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_560ms.java" @@ -0,0 +1,43 @@ +package 위상정렬; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; +// 위상정렬 안 쓴 위상정렬 문제 +public class Main_백준_14567_선수과목_골드5_함소연_560ms { + static ArrayList[] list; + static int[] degree; + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); // 과목의 수 + int M = Integer.parseInt(st.nextToken()); // 선수 조건의 수 + + list = new ArrayList[N+1]; + for (int i = 1; i <= N; i++) { + list[i] = new ArrayList(); + } + + degree = new int[N + 1]; // 진입 차수 + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list[b].add(a); + } + + for (int i = 1; i <= N; i++) { + for (int b : list[i]) { + degree[i] = Math.max(degree[i], degree[b]+1); // 최대 학기 + } + sb.append(degree[i]+1).append(" "); + } + System.out.println(sb.toString()); + } // end of main +} // end of class diff --git "a/\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" "b/\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" new file mode 100644 index 0000000..151d70d --- /dev/null +++ "b/\355\201\220/BOJ_13335_\355\212\270\353\237\255.java" @@ -0,0 +1,49 @@ +package 큐; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class BOJ_13335_트럭 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + Queue queue = new LinkedList(); + Queue bridge = new LinkedList(); + + int N = Integer.parseInt(st.nextToken()); + int W = Integer.parseInt(st.nextToken()); + int L = Integer.parseInt(st.nextToken()); + + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + queue.offer(Integer.parseInt(st.nextToken())); + } + + for (int i = 0; i < W; i++) { + bridge.offer(0); + } + + int l = 0; // 무게 + int time = 0; // 시간 + + while (!bridge.isEmpty()) { + time++; + l -= bridge.poll(); // 다리에서 빠져 나감 + if(!queue.isEmpty()) { + // 다리 위를 지나갈 수 있는 경우 + if(queue.peek() + l <= L) { + l += queue.peek(); + bridge.offer(queue.poll()); + }else { + bridge.offer(0); + } + } + } + System.out.println(time); + } +} diff --git "a/\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" "b/\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" new file mode 100644 index 0000000..163a67e --- /dev/null +++ "b/\355\201\220/BOJ_14713_\354\225\265\353\254\264\354\203\210.java" @@ -0,0 +1,57 @@ +package 큐; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; +/** + * + * 큐리스트 + * + */ +public class BOJ_14713_앵무새 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + Queue check = new LinkedList<>(); + Queue arr[]; + int N = Integer.parseInt(br.readLine()); + arr = new LinkedList[N]; + int sum = 0; + for (int i = 0; i < N; i++) { + arr[i] = new LinkedList(); + String s = br.readLine(); + String[] srr = s.split(" "); + sum+= srr.length; + for(int j = 0; j < srr.length; j++) { + arr[i].offer(srr[j]); + } + } + + String a = br.readLine(); + String[] ans = a.split(" "); + + // 반례 : 받아적은 문장과 앵무새가 말한 단어의 개수가 다를 때. + if(sum != ans.length) {System.out.println("Impossible"); return;} + + boolean flag = false; + for (int i = 0; i < ans.length; i++){ + flag = false; + for (int j = 0; j < N; j++) { + if(ans[i].equals(arr[j].peek())) { + arr[j].poll(); + flag = true; + break; + } + } + if(!flag) break; + } + + if(flag) System.out.println("Possible"); + else System.out.println("Impossible"); + + } // end of main +} // end of class diff --git "a/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" "b/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" new file mode 100644 index 0000000..fb4fc1d --- /dev/null +++ "b/\355\212\270\353\246\254/BOJ_1068_\355\212\270\353\246\254.java" @@ -0,0 +1,69 @@ +package 트리; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class BOJ_1068_트리 { + + static int[] tree; + static ArrayList child[]; + static int cnt = 0; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + int root = 0; + tree = new int[N]; + child = new ArrayList[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + child[i] = new ArrayList(); + } + for (int i = 0; i < N; i++) { + tree[i] = Integer.parseInt(st.nextToken()); + if(tree[i] == -1) { // 부모노드가 없으면 루트노드 + root = i; + continue; + } + child[tree[i]].add(i); // 자식 노드에 부모 노드 정보 + } + + int del = Integer.parseInt(br.readLine()); + + // 루트노드를 지우는 것이 아니라면, + if(del != root) { + delete(del); + search(root); + }else { + System.out.println(cnt); + return; + } + System.out.println(cnt); + + + } + public static void search(int node) { + // 자식이 없으면 리프노드 + if(child[node].size() == 0) { + cnt++; + return; + } + // 자식까지 탐색 + for (int i = 0; i < child[node].size(); i++) { + search(child[node].get(i)); + } + } + + public static void delete(int del) { + for (int i = 0; i < child[tree[del]].size(); i++) { + if(child[tree[del]].get(i) == del) { + child[tree[del]].remove(i); + break; + } + } + } + +} diff --git "a/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" "b/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" new file mode 100644 index 0000000..76f0edd --- /dev/null +++ "b/\355\212\270\353\246\254/BOJ_1991_\355\212\270\353\246\254\354\210\234\355\232\214.java" @@ -0,0 +1,64 @@ +package 트리; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BOJ_1991_트리순회 { + static int[][] tree; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + tree = new int[26][2]; + + + for (int i = 0; i < N; i++) { + String[] temp = br.readLine().split(" "); + int node = temp[0].charAt(0) - 'A'; + char left = temp[1].charAt(0); + char right = temp[2].charAt(0); + if(left == '.') { // 왼쪽에 자식 노드가 없음 + tree[node][0] = -1; + }else { + tree[node][0] = left -'A'; + } + + if(right == '.') { // 오른쪽에 자식 노드가 없음 + tree[node][1] = -1; + }else { + tree[node][1] = right - 'A'; + } + } + preOrder(0); + sb.append("\n"); + inOrder(0); + sb.append("\n"); + postOrder(0); + sb.append("\n"); + System.out.println(sb); + } + /** 가운데 - 왼쪽 - 오른쪽 */ + public static void preOrder(int i) { + if(i == -1) return; // 자식노드가 없으면 종료 + sb.append((char) (i + 'A')); // 현재 + preOrder(tree[i][0]); // 왼쪽 + preOrder(tree[i][1]); // 오른쪽 + } + /** 왼쪽 - 가운데 - 오른쪽 */ + public static void inOrder(int i) { + if(i == -1) return; // 자식노드가 없으면 종료 + inOrder(tree[i][0]); // 왼쪽 + sb.append((char) (i + 'A')); // 현재 + inOrder(tree[i][1]); // 오른쪽 + } + /** 왼쪽 - 오른쪽 - 가운데 */ + public static void postOrder(int i) { + if(i == -1) return; // 자식노드가 없으면 종료 + postOrder(tree[i][0]); // 왼쪽 + postOrder(tree[i][1]); // 오른쪽 + sb.append((char) (i + 'A')); // 현재 + } + +} From 13b1820b9301b83c6de9442e0706db34d5786931 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 28 Feb 2023 01:18:37 +0900 Subject: [PATCH 21/30] =?UTF-8?q?2=EC=9B=945=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\223\234\354\233\214\354\205\234.java" | 80 +-------------- ...00_17829_222\355\222\200\353\247\201.java" | 20 +--- ...\353\223\234\355\212\270\353\246\254.java" | 7 -- ...25\250\354\206\214\354\227\260_772ms.java" | 95 ++++++++++++++++++ ...25\250\354\206\214\354\227\260_240ms.java" | 75 ++++++++++++++ ...25\250\354\206\214\354\227\260_524ms.java" | 60 +++++++++++ ...25\250\354\206\214\354\227\260_552ms.java" | 86 ++++++++++++++++ ...25\250\354\206\214\354\227\260_804ms.java" | 69 +++++++++++++ ...5\250\354\206\214\354\227\260_1652ms.java" | 96 ++++++++++++++++++ ...5\250\354\206\214\354\227\260_1628ms.java" | 94 ++++++++++++++++++ ...\352\260\204\354\264\210\352\263\274.java" | 99 +++++++++++++++++++ 11 files changed, 679 insertions(+), 102 deletions(-) create mode 100644 "\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_10282_\355\225\264\355\202\271_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_772ms.java" create mode 100644 "\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_11657_\355\203\200\354\236\204\353\250\270\354\213\240_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_240ms.java" create mode 100644 "\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1613_\354\227\255\354\202\254_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_524ms.java" create mode 100644 "\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1956_\354\232\264\353\217\231_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_552ms.java" create mode 100644 "\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_16398_\355\226\211\354\204\261\354\227\260\352\262\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_804ms.java" create mode 100644 "\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_1774_\354\232\260\354\243\274\354\213\240\352\263\274\354\235\230\352\265\220\352\260\220_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_1652ms.java" create mode 100644 "\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_1628ms.java" create mode 100644 "\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" diff --git "a/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" index 31278f6..e1a8dee 100644 --- "a/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" +++ "b/BFS/Main_\353\260\261\354\244\200_1389_\354\274\200\353\271\210\353\262\240\354\235\264\354\273\250\354\235\2306\353\213\250\352\263\204\353\262\225\354\271\231_\355\224\214\353\241\234\354\235\264\353\223\234\354\233\214\354\205\234.java" @@ -1,81 +1,4 @@ -<<<<<<< HEAD - - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayDeque; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.Queue; -import java.util.StringTokenizer; - -/** 플로이드 워셜 O(n^3) */ -public class Main_백준_1389_케빈베이컨의6단계법칙_플로이드워셜 { - static int[][] list; - static int[][] bridge; - static int N, M, ans, sum; - static StringBuilder sb = new StringBuilder(); - static int min = Integer.MAX_VALUE; - static int INF = 100; - - public static void main(String[] args) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); - - list = new int[N + 1][N + 1]; - bridge = new int[N + 1][N + 1]; - for (int i = 0; i < M; i++) { - st = new StringTokenizer(br.readLine()); - int a = Integer.parseInt(st.nextToken()); - int b = Integer.parseInt(st.nextToken()); - list[a][b] = 1; // 양방향 - list[b][a] = 1; - } - // 배열 초기화 - for (int i = 1; i <= N; i++) { - for (int j = 1; j <= N; j++) { - if (i == j) - continue; - else if (list[i][j] == 1) - bridge[i][j] = 1; - else - bridge[i][j] = INF; - } - } - FloydWarshall(); - // 케빈 베이컨의 수가 가장 작은 사람 - for (int i = 1; i <= N; i++) { - sum = 0; - for (int j = 1; j <= N; j++) { - sum += bridge[i][j]; - } - if (min > sum) { - min = sum; - ans = i; - } - } - System.out.println(ans); - } // end of main - - /** 플로이드 워셜 */ - public static void FloydWarshall() { - for (int k = 1; k <= N; k++) { // k : 중간 다리 - for (int i = 1; i <= N; i++) { // i부터 j까지 갈때 중간다리 k를 건널지 말지 (작으면 건넘) - for (int j = 1; j <= N; j++) { - bridge[i][j] = Math.min(bridge[i][j], bridge[i][k] + bridge[k][j]); - } - } - } - } - -======= -package study; +package BFS; import java.io.BufferedReader; import java.io.IOException; @@ -150,5 +73,4 @@ public static void FloydWarshall() { } } ->>>>>>> 284d4774554f0459225244fbcaa9364bb33bb571 } // end of class \ No newline at end of file diff --git "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" index 667bf04..dd29607 100644 --- "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" +++ "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_17829_222\355\222\200\353\247\201.java" @@ -21,13 +21,9 @@ public static void main(String[] args) throws NumberFormatException, IOException } } System.out.println(Pooling(N, 0, 0)); -<<<<<<< HEAD } // end of main - -======= - - } // end of main ->>>>>>> 284d4774554f0459225244fbcaa9364bb33bb571 + + public static int Pooling(int N, int x, int y) { if(N == 2) { return FindSecond(N, x, y); @@ -41,12 +37,9 @@ public static int Pooling(int N, int x, int y) { Arrays.sort(arr); return arr[2]; // 두 번째로 큰 수 } -<<<<<<< HEAD + } // end of Pooling - -======= - } ->>>>>>> 284d4774554f0459225244fbcaa9364bb33bb571 + public static int FindSecond(int N, int x, int y) { int[] arr = new int[4]; int idx = 0; @@ -57,10 +50,5 @@ public static int FindSecond(int N, int x, int y) { } Arrays.sort(arr); return arr[2]; // 두 번째로 큰 수 -<<<<<<< HEAD } // end of FindSecond } // end of class -======= - } -} ->>>>>>> 284d4774554f0459225244fbcaa9364bb33bb571 diff --git "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" index f62edb8..344366e 100644 --- "a/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" +++ "b/\353\266\204\355\225\240\354\240\225\353\263\265/Main_\353\260\261\354\244\200_1992_\354\277\274\353\223\234\355\212\270\353\246\254.java" @@ -33,17 +33,10 @@ public static void QuadTree(int N, int x, int y) { }else { sb.append("("); int N2 = N/2; -<<<<<<< HEAD QuadTree(N2, x, y); // (0, 0) QuadTree(N2, x, y + N2); // (0, 1) QuadTree(N2, x + N2, y); // (1, 0) QuadTree(N2, x + N2, y + N2); // (1, 1) -======= - QuadTree(N2, x, y); // (0, 0) - QuadTree(N2, x, y + N2); // (0, 1) - QuadTree(N2, x + N2, y); // (1, 0) - QuadTree(N2, x + N2, y + N2); // (1, 1) ->>>>>>> 284d4774554f0459225244fbcaa9364bb33bb571 sb.append(")"); } diff --git "a/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_10282_\355\225\264\355\202\271_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_772ms.java" "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_10282_\355\225\264\355\202\271_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_772ms.java" new file mode 100644 index 0000000..7fc7208 --- /dev/null +++ "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_10282_\355\225\264\355\202\271_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_772ms.java" @@ -0,0 +1,95 @@ +package 최단경로; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +/** 다익스트라 + 우선순위 큐 */ +public class Main_백준_10282_해킹_골드4_함소연_772ms { + static StringBuilder sb = new StringBuilder(); + static boolean isVisited[]; + static int cnt = 0, totalTime = 0; + static int[] time; + static ArrayList[] list; + static class Node implements Comparable{ + int n; + int t; + public Node(int n, int t) { + this.n = n; + this.t = t; + } + public int compareTo(Node o) { + return this.t - o.t; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); // 테스트케이스 개수 + + for (int tc = 1; tc <= T; tc++) { + st = new StringTokenizer(br.readLine(), " "); + int N = Integer.parseInt(st.nextToken()); // 컴퓨터 개수 + int D = Integer.parseInt(st.nextToken()); // 의존성 개수 + int C = Integer.parseInt(st.nextToken()); // 해킹당한 컴퓨터 번호 + + time = new int[N+1]; // 소요 시간 저장 배열 + list = new ArrayList[N+1]; + for (int i = 0; i < N+1; i++) { + time[i] = Integer.MAX_VALUE; + list[i] = new ArrayList(); + } + + for (int i = 0; i < D; i++) { + st = new StringTokenizer(br.readLine(), " "); + int a = Integer.parseInt(st.nextToken()); // a컴퓨터 + int b = Integer.parseInt(st.nextToken()); // b컴퓨터 // a가 b를 의존 + int t = Integer.parseInt(st.nextToken()); // b가 감염되면 s초 후 a 감염 + list[b].add(new Node(a, t)); + } + + cnt = 0; // 감염된 컴퓨터 수 + totalTime = 0; // 시간 + isVisited = new boolean[N+1]; + Dijkstra(C); + + for (int i = 0; i < N+1; i++) { + if(time[i] != Integer.MAX_VALUE) { + totalTime = Math.max(totalTime, time[i]); // 최대 소요 시간 => total + } + } + + sb.append(cnt).append(" ").append(totalTime).append("\n"); + } // end of testcase + System.out.println(sb.toString()); + } // end of main + + private static void Dijkstra(int start) { + PriorityQueue pq = new PriorityQueue(); + + pq.offer(new Node(start, 0)); + time[start] = 0; + + while(pq.size() != 0) { + Node node = pq.poll(); + if(isVisited[node.n]) continue; + isVisited[node.n] = true; + cnt++; + for (Node next : list[node.n]) { + // 다른 노드를 거쳐가는 것이 더 시간이 적은지 확인 + // 저장된 소요 시간 > 현재 소요 시간 + 다음 소요 시간 + // 더 작으면 갱신 + if(time[next.n] > time[node.n] + next.t) { + time[next.n] = time[node.n] + next.t; + pq.add(new Node(next.n, time[next.n])); + } + } + } + + } + +} // end of class diff --git "a/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_11657_\355\203\200\354\236\204\353\250\270\354\213\240_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_240ms.java" "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_11657_\355\203\200\354\236\204\353\250\270\354\213\240_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_240ms.java" new file mode 100644 index 0000000..6c35c29 --- /dev/null +++ "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_11657_\355\203\200\354\236\204\353\250\270\354\213\240_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_240ms.java" @@ -0,0 +1,75 @@ +package 최단경로; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** 벨만 포드 : 음수가중치 */ +public class Main_백준_11657_타임머신_골드4_함소연_240ms { + static long[] dist; + static ArrayList list; + private static int N; + private static int M; + static class Node{ + int a; + int b; + int cost; + public Node(int a, int b, int cost) { + this.a = a; + this.b = b; + this.cost = cost; + } + } + public static void main(String[] args) throws IOException { + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 도시의 개수 + M = Integer.parseInt(st.nextToken()); // 버스 노선의 개수 + + dist = new long[N+1]; // 최단 거리 배열 + Arrays.fill(dist, Long.MAX_VALUE); + + list = new ArrayList<>(); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); // 시작 도시 + int b = Integer.parseInt(st.nextToken()); // 도착 도시 + int c = Integer.parseInt(st.nextToken()); // 이동 시간 + + list.add(new Node(a, b, c)); + } + + if(BellmanFord(1)) { + System.out.println(-1); + return; + } + + for (int i = 2; i < dist.length; i++) { + if(dist[i] == Long.MAX_VALUE) { // 가는 경로가 없음 + sb.append(-1).append("\n"); + } + else sb.append(dist[i]).append("\n"); // 가는 경로 존재 + } + System.out.println(sb.toString()); + } // end of main + private static boolean BellmanFord(int start) { + dist[start] = 0; + for (int i = 0; i < N; i++) { // 정점의 개수만큼 + for (int j = 0; j < M; j++) { // 간선의 개수만큼 + Node node = list.get(j); + // 최단 경로 갱신 + if(dist[node.a] != Long.MAX_VALUE && dist[node.b] > dist[node.a] + node.cost) { + dist[node.b] = dist[node.a] + node.cost; + if(i == N-1) return true; + } + } + } + return false; + } +} // end of class diff --git "a/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1613_\354\227\255\354\202\254_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_524ms.java" "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1613_\354\227\255\354\202\254_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_524ms.java" new file mode 100644 index 0000000..2cf890c --- /dev/null +++ "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1613_\354\227\255\354\202\254_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_524ms.java" @@ -0,0 +1,60 @@ +package 최단경로; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** 플로이드 워셜 */ +public class Main_백준_1613_역사_골드3_함소연_524ms { + static int[][] graph; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + StringBuilder sb = new StringBuilder(); + + int N = Integer.parseInt(st.nextToken()); // 사건 개수 + int K = Integer.parseInt(st.nextToken()); // 관계 개수 + + graph = new int[N+1][N+1]; + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine(), " "); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + graph[a][b] = -1; // 정순 + graph[b][a] = 1; // 역순 + } + + // 플로이드 워셜 + // 경유지 k, 출발지 i, 도착지 j + for (int k = 1; k <= N; k++) { + for (int i = 1; i <= N; i++) { + if(i == k) continue; // 출발지와 경유지 겹침 + if(graph[i][k] == 0) continue; // 경유지 X + for (int j = 1; j <= N; j++) { + if(i == j || j == k) continue; // 출발지와 도착지 겹침, 경유지와 도착지 겹침 + if(graph[k][j] == 0) continue; // 경유지 X + if(graph[i][j] == 0) { // 경유지 탐색 + if(graph[i][k] == -1 && graph[k][j] == -1) { // 정순이면 -1 + graph[i][j] = -1; + } + if(graph[i][k] == 1 && graph[k][j] == 1) { // 역순이면 1 + graph[i][j] = 1; + } + } + } + } + } + int S = Integer.parseInt(br.readLine()); // 알고 싶은 사건 쌍의 수 + + for (int i = 0; i < S; i++) { + st = new StringTokenizer(br.readLine(), " "); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + sb.append(graph[a][b]).append("\n"); + } + + System.out.println(sb.toString()); + } +} diff --git "a/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1956_\354\232\264\353\217\231_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_552ms.java" "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1956_\354\232\264\353\217\231_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_552ms.java" new file mode 100644 index 0000000..44643fb --- /dev/null +++ "b/\354\265\234\353\213\250\352\262\275\353\241\234/Main_\353\260\261\354\244\200_1956_\354\232\264\353\217\231_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_552ms.java" @@ -0,0 +1,86 @@ +package 최단경로; + +/** + * 최단경로 4가지 + * 1. 하나의 정점에서 다른 하나의 정점까지의 최단경로 + * 2. 하나의 정점에서 다른 모든 정점까지의 최단경로 + * 3. 하나의 목적지로 가는 모든 최단경로 + * 4. 모든 최단경로 + * + * 최단경로 알고리즘 4가지 + * - BFS O(V + E) : 가중치 X, 노드간 최소 이동 횟수 (1, 2, 3, 4) + * - 다익스트라 O((V+E)logV) : 음의 가중치 X (1, 2, 3) + * - 벨만 포드 O(VE) : 음의 가중치 O (1, 2, 3) + * - 플로이드 워셜 O(N^3) : 음의 가중치 O (4) + */ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** + * 최단경로 : 플로이드 워셜 O(N^3) + * - 모든 점에서 모든 점으로의 최단 거리 + * - 현재 가려는 정점의 거리가 다른 점을 거쳐서 가는 것보다 멀다면, + * - 거쳐서 가는 거리값 저장 + * - 음의 가중치 사용 가능 + * - Math.min((시작점 + 끝점), (시작점 + 중간점 + 끝점)) + */ +public class Main_백준_1956_운동_골드4_함소연_552ms { + static boolean[] isVisited; + static int[][] graph; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int V = Integer.parseInt(st.nextToken()); // 마을의 개수 + int E = Integer.parseInt(st.nextToken()); // 도로의 개수 + + graph = new int[V+1][V+1]; + + for (int i = 1; i <= V; i++) { + Arrays.fill(graph[i], Integer.MAX_VALUE); + graph[i][i] = 0; + } + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); // 가중치 + + if(graph[a][b] > w) { + graph[a][b] = w; + } + } + + // 플로이드 워셜 + // 시작점 : i, 중간점 : k, 끝점 : j + // 모든 노드를 중간점으로 지정하여 모든 노드의 최단 거리를 구한다. + for (int k = 1; k <= V; k++) { + for (int i = 1; i <= V; i++) { + if(graph[i][k] == Integer.MAX_VALUE) continue; + for (int j = 1; j <= V; j++) { + if(graph[k][j] == Integer.MAX_VALUE) continue; + graph[i][j] = Math.min(graph[i][j], graph[i][k] + graph[k][j]); + } + } + } + + // 사이클 존재 확인 + int ans = Integer.MAX_VALUE; + for (int i = 1; i <= V; i++) { + for (int j = 1; j <= V; j++) { + if(i == j) continue; + // 두 도시끼리 왕복할 수 있는 도로가 있음 => 사이클 존재 + if(graph[i][j] != Integer.MAX_VALUE && graph[j][i] != Integer.MAX_VALUE) { + ans = Math.min(ans, graph[i][j] + graph[j][i]); + } + } + } + + ans = ans == Integer.MAX_VALUE ? - 1: ans; + System.out.println(ans); + } // end of main +} // end of class diff --git "a/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_16398_\355\226\211\354\204\261\354\227\260\352\262\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_804ms.java" "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_16398_\355\226\211\354\204\261\354\227\260\352\262\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_804ms.java" new file mode 100644 index 0000000..d568b82 --- /dev/null +++ "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_16398_\355\226\211\354\204\261\354\227\260\352\262\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_804ms.java" @@ -0,0 +1,69 @@ +package 최소신장트리; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +/** 프림 알고리즘 */ +public class Main_백준_16398_행성연결_골드4_함소연_804ms { + static int[][] graph; + static boolean[] isVisited; + static int N; + static long ans; + + static class Node implements Comparable{ + int v; + int w; + public Node(int v, int w) { + this.v = v; + this.w = w; + } + + @Override + public int compareTo(Node o) { + return this.w - o.w; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); // 행성의 수 + graph = new int[N][N]; + + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + graph[i][j] = Integer.parseInt(st.nextToken()); + } + } + + Prim(0); + System.out.println(ans); + } // end of main + + private static void Prim(int start) { + PriorityQueue pq = new PriorityQueue<>(); + isVisited = new boolean[N]; + + pq.offer(new Node(start, 0)); + + while(pq.size() != 0) { + Node node = pq.poll(); + + if(!isVisited[node.v]) { + isVisited[node.v] = true; + ans += node.w; + for (int i = 0; i < N; i++){ + if(i == node.v) continue; + if(!isVisited[i]) { + pq.offer(new Node(i, graph[node.v][i])); + } + } + } + } + } // end of Prim +} // end of class diff --git "a/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_1774_\354\232\260\354\243\274\354\213\240\352\263\274\354\235\230\352\265\220\352\260\220_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_1652ms.java" "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_1774_\354\232\260\354\243\274\354\213\240\352\263\274\354\235\230\352\265\220\352\260\220_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_1652ms.java" new file mode 100644 index 0000000..4f05751 --- /dev/null +++ "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_1774_\354\232\260\354\243\274\354\213\240\352\263\274\354\235\230\352\265\220\352\260\220_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_1652ms.java" @@ -0,0 +1,96 @@ +package 최소신장트리; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_1774_우주신과의교감_골드3_함소연_1652ms { + static int[][] pos; + static int[] parent; + private static double[][] map; + public static int[] numbers; + static double total = 0; + private static int N, idx = 0; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + + pos = new int[N][2]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + pos[i][0] = Integer.parseInt(st.nextToken()); + pos[i][1] = Integer.parseInt(st.nextToken()); + } + + numbers = new int[2]; + int size = ((N + 1) * N) / 2; + map = new double[size][3]; + comb(0, 0); + + Arrays.sort(map, (o1, o2) -> Double.compare(o1[2], o2[2])); + + parent = new int[N]; + for (int i = 0; i < N; i++) { + parent[i] = i; + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()) - 1; + int b = Integer.parseInt(st.nextToken()) - 1; + union(a, b); + } + + for (int i = 0; i < size; i++) { + if (find((int) map[i][0]) != find((int) map[i][1])) { + union((int) map[i][0], (int) map[i][1]); + total += map[i][2]; + } + } + System.out.printf("%.2f", total); + } // end of main + + private static int find(int x) { + if (parent[x] == x) + return x; + return parent[x] = find(parent[x]); + } + + private static void union(int x, int y) { + int px = find(x); + int py = find(y); + + if (px > py) { + parent[py] = px; + } else { + parent[px] = py; + } + } + + private static double getDist(int x1, int y1, int x2, int y2) { + long x = Math.abs(x1 - x2); + long y = Math.abs(y1 - y2); + return Math.sqrt(x * x + y * y); + } + + public static void comb(int cnt, int start) { + if (cnt == 2) { + double dist = getDist(pos[numbers[0]][0], pos[numbers[0]][1], pos[numbers[1]][0], pos[numbers[1]][1]); + map[idx][0] = numbers[0]; + map[idx][1] = numbers[1]; + map[idx][2] = dist; + idx++; + return; + } + for (int i = start; i < N; i++) { + numbers[cnt] = i; + comb(cnt + 1, i); + } + } +} // end of class diff --git "a/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_1628ms.java" "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_1628ms.java" new file mode 100644 index 0000000..acb57c9 --- /dev/null +++ "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_1628ms.java" @@ -0,0 +1,94 @@ +package 최소신장트리; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; +import java.util.StringTokenizer; +/** + * 최소 신장 트리 : 프림 O(ElogV) + * - 시작점에서 갈 수 있는 정점 중 가장 가중치가 작은 정점 연결 + * - 시작점과 연결된 정점들을 집합이라 할 때, + * - 이 집한에 속하지 않은 정점들에 대해 정점연결 반복 + * - 새로운 정점 연결할 때마다 아직 연결되지 않은 정점들에 대한 간선 추가 + * - Priority Queue를 이용한 최소 힙으로 구현 + * + * 크루스칼 : 정점이 많을 때 유리 + * 프림 : 간선이 많을 때 유리 + */ +public class Main_백준_21924_도시건설_골드4_함소연_1628ms { + static long total = 0; + static long ans = 0; + static boolean[] isVisited; + static ArrayList[] list; + static PriorityQueue pq; + private static int N; + static class Node implements Comparable{ + int v; + int w; + public Node(int v, int w) { + super(); + this.v = v; + this.w = w; + } + // 가중치 정렬 + @Override + public int compareTo(Node o) { + return this.w - o.w; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 건물의 개수 + int M = Integer.parseInt(st.nextToken()); // 도로의 개수 + + list = new ArrayList[N+1]; + for (int i = 0; i < N+1; i++) { + list[i] = new ArrayList<>(); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); // 가중치 + + list[a].add(new Node(b, w)); + list[b].add(new Node(a, w)); + total += w; + } + + Prim(1); + } // end of main + + public static void Prim(int start) { + isVisited = new boolean[N + 1]; + int cnt =0; + pq = new PriorityQueue<>(); // 우선순위 큐 + pq.offer(new Node(start, 0)); + + while(pq.size() != 0) { + Node node = pq.poll(); + + if(!isVisited[node.v]) { + isVisited[node.v] = true; + ans += node.w; + cnt++; + for (Node n : list[node.v]) { + if(!isVisited[n.v]) { + pq.offer(n); + } + } + } + } // end of while + // 건물의 개수 == cnt : 모든 건물이 연결되어 있음 + if(cnt == N) System.out.println(total - ans); + else System.out.println(-1); + } // end of Prim +} // end of class diff --git "a/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" new file mode 100644 index 0000000..f5d03c6 --- /dev/null +++ "b/\354\265\234\354\206\214\354\213\240\354\236\245\355\212\270\353\246\254/Main_\353\260\261\354\244\200_21924_\353\217\204\354\213\234\352\261\264\354\204\244_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" @@ -0,0 +1,99 @@ +package 최소신장트리; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; +import java.util.StringTokenizer; +/** + * 최소 신장 트리 : 크루스칼 O(ElogE) + * - 정점 N개를 가지는 그래프에서 N-1개의 간선을 연결해야 한다. + * - 모든 정점이 연결되어야 하나, 싸이클이 되면 안됨. + * - union(), find()로 싸이클 여부를 찾음. + */ +public class Main_백준_21924_도시건설_골드4_함소연_시간초과 { + static int[][] graph; + static int[] parent; + static long total = 0; + static long ans = 0; + static boolean[] isVisited; + /** 싸이클 여부를 찾음 */ + public static void union(int a, int b) { + int parentA = find(a); + int parentB = find(b); + + if(parentA < parentB) + parent[parentB] = parentA; + else + parent[parentA] = parentB; + + } + + public static int find(int i) { + if (parent[i] == i) // 부모가 맞음 + return i; + return find(parent[i]); + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); // 건물의 개수 + int M = Integer.parseInt(st.nextToken()); // 도로의 개수 + + graph = new int[M][3]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); // 가중치 + graph[i][0] = a; + graph[i][1] = b; + graph[i][2] = w; + total += w; + } + + + // 가중치 정렬 + Arrays.sort(graph, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + return o1[2] - o2[2]; + } + }); + + // 연결 여부 확인 && 부모 노드 저장 + parent = new int[N+1]; + isVisited = new boolean[N+1]; + isConnected(1); + for (int i = 1; i < N+1; i++) { + parent[i] = i; // 부모 노드 저장 + if(!isVisited[i]) { + System.out.println(-1); + return; + } + } + + // 크루스칼 + for (int i = 0; i < graph.length; i++) { + // 둘의 부모가 같지 않으면 (싸이클이 없음) 간선 선택 + if(find(graph[i][0]) != find(graph[i][1])) { + ans += graph[i][2]; + union(graph[i][0], graph[i][1]); + } + // 둘의 부모가 같으면 (싸이클이 있음), 간선 비선택 + } + System.out.println(total - ans); + } + + public static void isConnected(int b) { + isVisited[b] = true; + for (int i = 0; i < graph.length; i++) { + if(graph[i][0] == b && !isVisited[graph[i][1]]) { + isConnected(graph[i][1]); + } + } + } +} From ba3c0ad8f5a2b9ae82d5a52263312a98934ed1ee Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 14 Mar 2023 00:30:13 +0900 Subject: [PATCH 22/30] =?UTF-8?q?3=EC=9B=942=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\250\354\206\214\354\227\260_140ms.java" | 171 +++++++++++++++++ ...225\250\354\206\214\354\227\260_80ms.java" | 109 +++++++++++ ...25\250\354\206\214\354\227\260_252ms.java" | 96 ++++++++++ ...25\250\354\206\214\354\227\260_224ms.java" | 162 ++++++++++++++++ ...25\250\354\206\214\354\227\260_312ms.java" | 177 ++++++++++++++++++ ...25\250\354\206\214\354\227\260_488ms.java" | 142 ++++++++++++++ ...225\250\354\206\214\354\227\260_96ms.java" | 111 +++++++++++ ...\355\225\250\354\206\214\354\227\260.java" | 7 + ...25\250\354\206\214\354\227\260_124ms.java" | 43 +++++ ...225\250\354\206\214\354\227\260_92ms.java" | 54 ++++++ ...225\250\354\206\214\354\227\260_88ms.java" | 47 +++++ ...\355\225\250\354\206\214\354\227\260.java" | 5 + ...25\250\354\206\214\354\227\260_616ms.java" | 60 ++++++ ...5\250\354\206\214\354\227\260_1016ms.java" | 52 +++++ ...\355\225\250\354\206\214\354\227\260.java" | 61 ++++++ ...25\250\354\206\214\354\227\260_632ms.java" | 64 +++++++ 16 files changed, 1361 insertions(+) create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_140ms.java" create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_80ms.java" create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_252ms.java" create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_224ms.java" create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_312ms.java" create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_488ms.java" create mode 100644 "A\355\230\225/Main_\353\260\261\354\244\200_17471_\352\262\214\353\246\254\353\247\250\353\215\224\353\247\201_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_96ms.java" create mode 100644 "A\355\230\225/Solution_SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" create mode 100644 "DP/Main_\353\260\261\354\244\200_12026_BOJ\352\261\260\353\246\254_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_92ms.java" create mode 100644 "DP/Main_\353\260\261\354\244\200_21317_\354\247\225\352\262\200\353\213\244\353\246\254\352\261\264\353\204\210\352\270\260_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_88ms.java" create mode 100644 "\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_19583_\354\213\270\354\235\264\353\262\204\352\260\234\352\260\225\354\264\235\355\232\214_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_616ms.java" create mode 100644 "\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_10815_\354\210\253\354\236\220\354\271\264\353\223\234_\354\213\244\353\262\2045_\355\225\250\354\206\214\354\227\260_1016ms.java" create mode 100644 "\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1374_\352\260\225\354\235\230\354\213\244_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_632ms.java" diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_140ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_140ms.java" new file mode 100644 index 0000000..1467760 --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_140ms.java" @@ -0,0 +1,171 @@ +package A형; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_16236_아기상어_골드3_함소연_140ms { + static class Pos { + int x; + int y; + int dist; + + public Pos(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } + + private static int minX; + private static int minY; + private static int[][] map; + private static int[] dx = { -1, 0, 1, 0 }; + private static int[] dy = { 0, -1, 0, 1 }; + private static int time = 0; + private static int shark = 2; + private static int N; + private static int x, y; + private static int minDist; + private static int[][] dist; + private static int cnt; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + StringTokenizer st; + dist = new int[N][N]; + map = new int[N][N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if (map[i][j] == 9) { + x = i; + y = j; + map[i][j] = 0; + } + } + } + go(); + System.out.println(time); + } + + public static void go() { + while (true) { + init(); // 초기화 +// if (!checkCatch()) +// return; + bfs(); + // 먹을 수 있는 물고기를 찾은 경우 + if (minX != Integer.MAX_VALUE && minY != Integer.MAX_VALUE) { + time += dist[minX][minY]; + cnt++; + // 먹은 수와 상어의 크기가 같으면 상어크기 증가 후 물고기 수 초기화 + if (cnt == shark) { + shark++; + cnt = 0; + } + map[minX][minY] = 0; // 먹은 물고기 위치를 0으로 + + // 상어 위치 갱신 + x = minX; + y = minY; + } else // 먹을 수 있는 물고기가 없는 경우 + return; + } + } + + // 잡을 수 있는 물고기가 있는 지 확인 + public static boolean checkCatch() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (map[i][j] != 0 && map[i][j] != 9 && map[i][j] < shark) + return true; + } + } + return false; + } + + // 지나갈 수 있는 지 확인 + public static boolean checkMove(int nx, int ny) { + if (nx < 0 || nx >= N || ny < 0 || ny >= N) + return false; // 범위 체크 + if (map[nx][ny] > shark) + return false; // 크기 체크 + return true; + } + + // 가장 가까운 물고기 찾기 + public static void bfs() { + Deque queue = new ArrayDeque(); + queue.offer(new Pos(x, y, 0)); + dist[x][y] = 0; + + while (queue.size() > 0) { + Pos p = queue.poll(); + for (int i = 0; i < 4; i++) { + int nx = p.x + dx[i]; + int ny = p.y + dy[i]; + // 범위 체크 + if (!checkMove(nx, ny)) + continue; + // 이미 방문했거나, 상어 크기보다 큰 물고기 건너 뛰기 + if (dist[nx][ny] != -1 || map[nx][ny] > shark) + continue; + // nx, ny에 있는 물고기까지의 이동거리 갱신 + dist[nx][ny] = dist[p.x][p.y] + 1; + // 먹을 수 있는 물고기일 경우 + if(map[nx][ny] != 0 && map[nx][ny] < shark) { + // 현재 물고기까지의 이동시간이 더 짧은 경우 + if (minDist > dist[nx][ny]) { + minX = nx; + minY = ny; + minDist = dist[nx][ny]; + // 현재 물고기까지의 이동시간이 같으면 가장 위쪽, 가장 왼쪽 찾기 + } else if (minDist == dist[nx][ny]) { + // 가장 위쪽에 있다면 가장 왼쪽인지 확인 + if (minX == nx) { + if (minY > ny) { + minX = nx; + minY = ny; + } + // 가장 위쪽인지 확인 + } else if (minX > nx) { + minX = nx; + minY = ny; + } + } + } + queue.offer(new Pos(nx, ny, dist[nx][ny])); + } + } + } + + public static void init() { + minDist = Integer.MAX_VALUE; + minX = Integer.MAX_VALUE; + minY = Integer.MAX_VALUE; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + dist[i][j] = -1; + } + } + } + +// public static void print() { +// for (int i = 0; i < N; i++) { +// for (int j = 0; j < N; j++) { +// if (i == x && j == y) +// System.out.print("■" + " "); +// else +// System.out.print(map[i][j] + " "); +// } +// System.out.println(); +// } +// } +} diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_80ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_80ms.java" new file mode 100644 index 0000000..469fb2c --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_80ms.java" @@ -0,0 +1,109 @@ +package A형; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Main_백준_16637_괄호추가하기_골드3_함소연_80ms { + private static int N; + private static char[] op; + private static int[] num; + private static int MAX = Integer.MIN_VALUE; + private static boolean[] isSelected; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + String str = br.readLine(); + op = new char[N / 2]; + num = new int[N / 2 + 1]; + int nIdx = 0, oIdx = 0; + for (int i = 0; i < N; i++) { + if(i % 2 == 0) { + num[nIdx++] = str.charAt(i) - '0'; + }else { + op[oIdx++] = str.charAt(i); + } + } + isSelected = new boolean[N / 2]; + go(0); + System.out.println(MAX); + } + + private static void go(int idx) { + if(idx == N/2) { + for (int i = 0; i < isSelected.length - 1; i++) { + if(isSelected[i] && isSelected[i+1]) { + return; + } + } + Cal(); + return; + } + + isSelected[idx] = true; + go(idx + 1); + isSelected[idx] = false; + go(idx + 1); + } + + private static void Cal() { + // 괄호 계산 + int total = 0; + int[] temp = Arrays.copyOf(num, num.length); + for (int i = 0; i < isSelected.length; i++) { + if(!isSelected[i]) continue; + switch (op[i]) { + case '-': + temp[i] = num[i] - num[i+1]; + temp[i+1] = 100; // pass + total++; + break; + case '+': + temp[i] = num[i] + num[i+1]; + temp[i+1] = 100; // pass + total++; + break; + case '*': + temp[i] = num[i] * num[i+1]; + temp[i+1] = 100; // pass + total++; + break; + default: + break; + } + } + // 최종 계산 + int idx = 0; + int[] newNum = new int[N / 2 + 1 - total]; + for (int i = 0; i < temp.length; i++) { + if(temp[i] == 100) continue; + newNum[idx++] = temp[i]; + } + idx = 0; + char[] newOp = new char[N / 2 - total]; + for (int i = 0; i < op.length; i++) { + if(isSelected[i]) continue; + newOp[idx++] = op[i]; + } + int res = newNum[0]; + for (int i = 0; i < newOp.length; i++) { + switch (newOp[i]) { + case '-': + res -= newNum[i+1]; + break; + case '+': + res += newNum[i+1]; + break; + case '*': + res *= newNum[i+1]; + break; + default: + break; + } + } + MAX = Math.max(MAX, res); + } +} + diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_252ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_252ms.java" new file mode 100644 index 0000000..538f06c --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_252ms.java" @@ -0,0 +1,96 @@ +package A형; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_17070_파이프옮기기1_골드5_함소연_252ms { + static int[] position = { 0, 1, 2 }; // 0 : 가로, 1 : 세로, 2 : 대각선 + private static int N; + private static int total; + private static int[][] map; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + map = new int[N][N]; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + move(0, 1, 0); + System.out.println(total); + } + + private static void move(int x, int y, int pos) { + if (x == N - 1 && y == N - 1) { + total++; + return; + } + switch (pos) { + case 0: + // 가로 + horizontal(x, y); + // 대각선 + diagonal(x, y); + break; + case 1: + // 세로 + vertical(x, y); + // 대각선 + diagonal(x, y); + break; + case 2: + // 가로 + horizontal(x, y); + // 세로 + vertical(x, y); + // 대각선 + diagonal(x, y); + break; + default: + break; + } + } + + // 범위 체크 + public static boolean checkMove(int x, int y, int pos) { + if (x < 0 || x >= N || y < 1 || y >= N || map[x][y] == 1) return false; + // 대각선 체크 + if(pos == 2) { + if(map[x][y-1] == 1 || map[x-1][y] == 1) return false; + } + return true; + } + // 가로 + public static void horizontal(int x, int y) { + int nx = x; + int ny = y + 1; + if (checkMove(nx, ny, 0)) { + move(nx, ny, 0); + } + } + // 세로 + public static void vertical(int x, int y) { + int nx = x + 1; + int ny = y; + if (checkMove(nx, ny, 1)) { + move(nx, ny, 1); + } + } + // 대각선 + public static void diagonal(int x, int y) { + int nx = x + 1; + int ny = y + 1; + if (checkMove(nx, ny, 2)) { + move(nx, ny, 2); + } + } + +} diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_224ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_224ms.java" new file mode 100644 index 0000000..eced87a --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_224ms.java" @@ -0,0 +1,162 @@ +package A형; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.Set; +import java.util.StringTokenizer; + +/* + * 궁수 3명 + * 하나의 칸에는 1명의 궁수 + * 턴마다 궁수는 적 하나 공격 + * 모든 궁수는 동시 공격 + * 거리가 D이하인 적 중에서 가장 가까운 적, 여러 명이면 가장 왼쪽에 있는 적 공격 + * 같은 적이 여러 궁수에게 공격당할 수 있음 + * 공격이 끝나면 적은 아래로 한 칸 이동 + * 성에 도달하면 제외 + * 모든 적이 제외되면 게임 끝 + * + */ +public class Main_백준_17135_캐슬디펜스_골드3_함소연_224ms{ + static class Pos{ + int x; + int y; + int dist; + public Pos(int x, int y, int dist) { + super(); + this.x = x; + this.y = y; + this.dist = dist; + } + } + private static int[][] map; + private static int[][] archers; + private static boolean[][] isCatched; + private static int[] dx = { 0, -1, 0}; + private static int[] dy = { -1, 0, 1}; // 좌 상 우 + private static int D; + private static int M; + private static int N; + private static int MAX = Integer.MIN_VALUE; + private static int die; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + + map = new int[N+1][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + archers = new int[3][2]; + + // 궁수 좌표 설정 + setPos(0, 0, 3); + System.out.println(MAX); + } + + private static void setPos(int idx, int start, int R) { + if (idx == R) { + Run(); + return; + } + + for (int i = start; i < M; i++) { + archers[idx][0] = N; + archers[idx][1] = i; + setPos(idx + 1, i + 1, R); + } + } + + + private static void Run() { + die = 0; + + // 원본 배열 복사 + int[][] round = new int[N+1][M]; + for (int i = 0; i < N + 1; i++) { + for (int j = 0; j < M; j++) { + round[i][j] = map[i][j]; + } + } + + while (true) { + if (checkClear()) { // 적이 map에 없다면 + MAX = Math.max(MAX, die); + map = round; // map 복원 + return; // 적이 모두 나가면 종료 + } + + isCatched = new boolean[N+1][M]; + for (int i = 0; i < 3; i++) { + int x = archers[i][0]; + int y = archers[i][1]; + shoot(x, y); + } + // 잡은 궁수 표시 + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if(isCatched[i][j]) { + map[i][j] = 0; + } + } + } + map = nextTurn(); // 적이 아래로 이동 + } + } + private static void shoot(int x, int y) { + Deque queue = new ArrayDeque(); + int nx, ny; + queue.offer(new Pos(x, y, 0)); + while(queue.size() > 0) { + Pos p = queue.poll(); + if(p.dist == D) { // 최대 거리면 종료 + return; + } + for (int d = 0; d < 3; d++) { + nx = p.x + dx[d]; + ny = p.y + dy[d]; + if (nx < 0 || nx >= N || ny < 0 || ny >= M) continue; + if (map[nx][ny] == 1) { // 적 발견 시 종료 + if(!isCatched[nx][ny]) { // 공격하지 않은 적이라면 die, 이미 공격했다면 pass + isCatched[nx][ny] = true; + die++; + } + return; + }else { // 다시 탐색 + queue.offer(new Pos(nx, ny, p.dist+1)); + } + } + } + } + + private static boolean checkClear() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (map[i][j] != 0) + return false; + } + } + return true; + } + + public static int[][] nextTurn() { + int[][] temp = new int[N+1][M]; + for (int i = 0; i < N - 1; i++) { + for (int j = 0; j < M; j++) { + temp[i + 1][j] = map[i][j]; + } + } + return temp; + } +} diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_312ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_312ms.java" new file mode 100644 index 0000000..b982a86 --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_312ms.java" @@ -0,0 +1,177 @@ +package A형; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/* + * 미세먼지 확산 (모든 미세먼지가 동시에 이루어짐) + * 1. A/5 :남은 미세먼지 양 + * 2. A - A/5 * (확산된 방향 개수) + * 3. 공기청정기가 있는 칸은 확산 X + * + * 공기청정기 작동 + * 1. 공기청정기 기준 (x, y) ~ (N, y) 아래 행은 시계 방향 + * 2. 공기청정기 기준 (x-1, y) ~ (0, y) 윗 행은 반시계 방향 + */ +public class Main_백준_17144_미세먼지안녕_골드4_함소연_312ms { + private static int[] dx = {0, 0, 1, -1}; + private static int[] dy = {1, -1, 0, 0}; + private static int[][] room; + private static int[] airCleaner; + private static int amount = 0; + private static int R; + private static int C; + private static int T; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + R = Integer.parseInt(st.nextToken()); // 집 크기 R + C = Integer.parseInt(st.nextToken()); // 집 크기 C + T = Integer.parseInt(st.nextToken()); // T 초 후 + + int idx = 0; + airCleaner = new int[2]; + room = new int[R][C]; + for (int i = 0; i < R; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < C; j++) { + room[i][j] = Integer.parseInt(st.nextToken()); + if(room[i][j] == -1) { // 공기 청정기 + airCleaner[idx++] = i; + } + } + } + go(); + System.out.println(count()); + } + // 작동 + private static void go() { + // T초동안 작동 : T초가 되면 return; + int time = 0; + while(time < T) { + int[][] temp = new int[R][C]; + // 1. 미세먼지 확산 + spread(temp); + // 2. 공기청정기 작동 + on(temp); + time++; + room = temp; + } + } + // 미세먼지 확산 + private static void spread(int[][] temp) { + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + if(room[i][j] == 0 || room[i][j] == -1) continue; + + int cnt = 0; + // 미세먼지 발견 시 확산 + for (int k = 0; k < 4; k++) { + int nx = i + dx[k]; + int ny = j + dy[k]; + + // 범위 체크 + if(nx < 0 || nx >= R || ny < 0 || ny >= C || room[nx][ny] == -1) continue; + + // 해당 자리로 미세먼지 확산 + temp[nx][ny] += room[i][j] / 5; + cnt++; + } + + // 원래 있던 미세먼지 자리 갱신 + temp[i][j] += room[i][j] - (room[i][j] / 5) * cnt; + } + } + temp[airCleaner[0]][0] = -1; + temp[airCleaner[1]][0] = -1; + } + + // 공기청정기 작동 + private static void on(int[][] temp) { + int save1; int save2; int save3; + // 반시계 방향 + int x = airCleaner[0]; + save1 = temp[0][0]; + save2 = temp[x][C-1]; + save3 = temp[0][C-1]; + + for (int i = 0; i < C-1; i++) { + temp[0][i] = temp[0][i+1]; + } + + for (int i = x; i > 1; i--) { + temp[i][0] = temp[i-1][0]; + } + temp[x][0] = -1; // 공기청정기가 흡수 + + for (int i = C-1; i > 1; i--) { + temp[x][i] = temp[x][i-1]; + } + temp[x][1] = 0; // 공기 청정기를 통과하면 정화 + + for (int i = 0; i < x; i++) { + temp[i][C-1] = temp[i+1][C-1]; + } + + temp[1][0] = save1; + temp[x-1][C-1] = save2; + temp[0][C-2] = save3; + + // 시계 방향 + x = airCleaner[1]; + save1 = temp[x][C-1]; + save2 = temp[R-1][C-1]; + save3 = temp[R-1][0]; + + for (int i = C-1; i > 0; i--) { + temp[x][i] = temp[x][i-1]; + } + temp[x][1] = 0; // 공기 청정기를 통과하면 정화 + + for (int i = R-1; i > x; i--) { + temp[i][C-1] = temp[i-1][C-1]; + } + + for (int i = 0; i < C-1; i++) { + temp[R-1][i] = temp[R-1][i+1]; + } + temp[x][1] = 0; // 공기 청정기를 통과하면 정화 + + + for (int i = x; i < R-1; i++) { + temp[i][0] = temp[i+1][0]; + } + temp[x][0] = -1; // 공기청정기가 흡수 + + temp[x+1][C-1] = save1; + temp[R-1][C-2] = save2; + temp[R-2][0] = save3; + } + // 남아있는 미세먼지 양 + private static int count() { + amount = 0; + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + if(room[i][j] == 0 || room[i][j] == -1) continue; + amount += room[i][j]; + } + } + return amount; + } +// // 프린트 +// private static void print(int[][] arr) { +// for (int i = 0; i < R; i++) { +// for (int j = 0; j < C; j++) { +// if(arr[i][j] == -1) +// System.out.print("■"+" "); +// else System.out.print(arr[i][j] + " "); +// } +// System.out.println(); +// } +// System.out.println(); +// } +} diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_488ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_488ms.java" new file mode 100644 index 0000000..aac64e2 --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_488ms.java" @@ -0,0 +1,142 @@ +package A형; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_17281_야구공_골드4_함소연_488ms { + + private static int[][] game; + private static int[] numbers; + private static int[] players; + private static int N; + private static boolean[] isSelected; + private static int maxScore = Integer.MIN_VALUE; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + game = new int[N][9]; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 9; j++) { + game[i][j] = Integer.parseInt(st.nextToken()); + } + } + isSelected = new boolean[9]; + numbers = new int[8]; + players = new int[9]; + go(0); + System.out.println(maxScore); + } + + private static void go(int idx) { + if(idx == 8) { + for (int i = 0; i < 3; i++) { + players[i] = numbers[i]; + } + players[3] = 0; + for (int i = 3; i < 8; i++) { + players[i+1] = numbers[i]; + } + // 점수계산 + score(); + return; + } + // 순열 + for (int i = 1; i < 9; i++) { + if(isSelected[i]) continue; + isSelected[i] = true; + numbers[idx] = i; + go(idx + 1); + isSelected[i] = false; + } + } + + private static void score() { + int home = 0; + int inning = 0; + int idx = 0; + while(inning < N) { // 이닝 수 만큼 + int out = 0; + boolean[] ground = new boolean[3]; + while(out < 3 ) { // 3아웃시 경기 종료 + if(idx >= 9) { // 다시 1번 타자부터 + idx = 0; + } + switch (game[inning][players[idx]]) { + case 0: + out++; + break; + case 1: // 안타 + if(ground[2]) { + home++; + ground[2] = false; + } + if(ground[1]) { + ground[1] = false; + ground[2] = true; + } + if(ground[0]) { +// ground[0] = false; + ground[1] = true; + } + ground[0] = true; + break; + case 2: // 2루타 + if(ground[2]) { + home++; + ground[2] = false; + } + if(ground[1]) { + home++; +// ground[1] = false; + } + if(ground[0]) { + ground[0] = false; + ground[2] = true; + } + ground[1] = true; + break; + case 3: // 3루타 + if(ground[2]) { + home++; +// ground[2] = false; + } + if(ground[1]) { + home++; + ground[1] = false; + } + if(ground[0]) { + home++; + ground[0] = false; + } + ground[2] = true; + break; + case 4: // 홈런 + if(ground[2]) { + home++; + ground[2] = false; + } + if(ground[1]) { + home++; + ground[1] = false; + } + if(ground[0]) { + home++; + ground[0] = false; + } + home++; + break; + default: + break; + } // end of switch + idx++; + } // end of out + inning++; + } // end of inning + maxScore = Math.max(home, maxScore); + } +} diff --git "a/A\355\230\225/Main_\353\260\261\354\244\200_17471_\352\262\214\353\246\254\353\247\250\353\215\224\353\247\201_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_96ms.java" "b/A\355\230\225/Main_\353\260\261\354\244\200_17471_\352\262\214\353\246\254\353\247\250\353\215\224\353\247\201_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_96ms.java" new file mode 100644 index 0000000..b658c62 --- /dev/null +++ "b/A\355\230\225/Main_\353\260\261\354\244\200_17471_\352\262\214\353\246\254\353\247\250\353\215\224\353\247\201_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_96ms.java" @@ -0,0 +1,111 @@ +package A형; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_17471_게리맨더링_골드4_함소연_96ms { + static ArrayList[] list; + static int[] person; + static boolean[] isSelected; + private static int min = Integer.MAX_VALUE; + private static int N; + private static boolean[] isVisited; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); // 구역의 개수 + + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + person = new int[N + 1]; + for (int i = 1; i <= N; i++) { + person[i] = Integer.parseInt(st.nextToken()); + } + + list = new ArrayList[N + 1]; + for (int i = 0; i <= N; i++) { + list[i] = new ArrayList(); + } + + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine(), " "); + int n = Integer.parseInt(st.nextToken()); // 인접 구역 개수 + for (int j = 0; j < n; j++) { + int area = Integer.parseInt(st.nextToken()); + list[i].add(area); + } + } + + isSelected = new boolean[N + 1]; + + subSet(1); + System.out.println(min == Integer.MAX_VALUE ? -1 : min); + } + + public static void subSet(int idx) { + if (idx == N + 1) { + int A = 0; + int B = 0; + for (int i = 1; i <= N; i++) { + if (isSelected[i]) + A++; + else + B++; + } + if (A == N || B == N) + return; + if (check(A, true) && check(B, false)) { // true : A , false : B + getDiff(); + } + return; + } + isSelected[idx] = true; + subSet(idx + 1); // 사용 + isSelected[idx] = false; + subSet(idx + 1); // 미사용 + } + + private static boolean check(int size, boolean AorB) { + Deque queue = new ArrayDeque(); + int cnt = 1; + isVisited = new boolean[N + 1]; + for (int i = 1; i <= N; i++) { + if (isSelected[i] == AorB) { + isVisited[i] = true; + queue.offer(i); + break; + } + } + while (queue.size() > 0) { + int n = queue.poll(); + for (int x : list[n]) { + if (isSelected[x] == AorB && !isVisited[x]) { + isVisited[x] = true; + cnt++; + queue.offer(x); + } + } + } + if (cnt == size) + return true; + return false; + } + + private static void getDiff() { + int A = 0; + int B = 0; + for (int i = 1; i <= N; i++) { + if (isSelected[i]) + A += person[i]; + else + B += person[i]; + } + min = Math.min(min, Math.abs(A - B)); + } +} diff --git "a/A\355\230\225/Solution_SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250_\355\225\250\354\206\214\354\227\260.java" "b/A\355\230\225/Solution_SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..50c9d23 --- /dev/null +++ "b/A\355\230\225/Solution_SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,7 @@ +package A형; + +public class Solution_SWEA_2115_벌꿀채취_함소연 { + public static void main(String[] args) { + + } +} diff --git "a/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" "b/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" new file mode 100644 index 0000000..9edb884 --- /dev/null +++ "b/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" @@ -0,0 +1,43 @@ +package DP; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/** knapsack */ +public class Main_백준_1106_호텔_골드5_함소연_124ms { + private static int[][] arr; + private static int[] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + int C = Integer.parseInt(st.nextToken()); // 늘려야 하는 최소 고객 + int N = Integer.parseInt(st.nextToken()); // 홍보 가능한 도시 수 + + arr = new int[N+1][2]; + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine(), " "); + arr[i][0] = Integer.parseInt(st.nextToken()); + arr[i][1] = Integer.parseInt(st.nextToken()); + } + + dp = new int[100001]; + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= 100000; j++) { + if(j - arr[i][0] >= 0) // 범위 + dp[j] = Math.max(dp[j], dp[j - arr[i][0]] + arr[i][1]); + } + } + + for (int i = 1; i <= 100001; i++) { + if(dp[i] >= C) { // 적어도 C명 이상 고객 유치 + System.out.println(i); + break; + } + } + + } // end of main +} // end of class diff --git "a/DP/Main_\353\260\261\354\244\200_12026_BOJ\352\261\260\353\246\254_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_92ms.java" "b/DP/Main_\353\260\261\354\244\200_12026_BOJ\352\261\260\353\246\254_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_92ms.java" new file mode 100644 index 0000000..b71c443 --- /dev/null +++ "b/DP/Main_\353\260\261\354\244\200_12026_BOJ\352\261\260\353\246\254_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_92ms.java" @@ -0,0 +1,54 @@ +package DP; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Main_백준_12026_BOJ거리_실버1_함소연_92ms { + private static int[] dp; + private static char[] block; + private static int N; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); // 보도 블럭 수 + block = br.readLine().toCharArray(); + dp = new int[N]; + Arrays.fill(dp, 987654321); + jump(); + if(dp[N-1] == 987654321) { + System.out.println(-1); + }else { + System.out.println(dp[N - 1]); + } + } // end of main + + private static void jump() { + dp[0] = 0; + for (int i = 0; i < N - 1; i++) { + char now = block[i]; + switch (now) { + case 'B': + findNext(i, 'O'); + break; + case 'O': + findNext(i, 'J'); + break; + case 'J': + findNext(i, 'B'); + break; + default: + break; + } + } + } + private static void findNext(int i, char ch) { + for (int j = i+1; j < N; j++) { + char next = block[j]; + if(next == ch) { + dp[j] = Math.min(dp[j], dp[i] + (j - i) * (j - i)); + } + } + } +} // end of class diff --git "a/DP/Main_\353\260\261\354\244\200_21317_\354\247\225\352\262\200\353\213\244\353\246\254\352\261\264\353\204\210\352\270\260_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_88ms.java" "b/DP/Main_\353\260\261\354\244\200_21317_\354\247\225\352\262\200\353\213\244\353\246\254\352\261\264\353\204\210\352\270\260_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_88ms.java" new file mode 100644 index 0000000..2cb374d --- /dev/null +++ "b/DP/Main_\353\260\261\354\244\200_21317_\354\247\225\352\262\200\353\213\244\353\246\254\352\261\264\353\204\210\352\270\260_\354\213\244\353\262\2041_\355\225\250\354\206\214\354\227\260_88ms.java" @@ -0,0 +1,47 @@ +package DP; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_21317_징검다리건너기_실버1_함소연_88ms { + private static int[][] arr; + private static int min = 987654321; + private static int N; + private static int K; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + arr = new int[N+1][2]; + for (int i = 1; i <= N - 1; i++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + int s = Integer.parseInt(st.nextToken()); // 바위 번호 + int l = Integer.parseInt(st.nextToken()); // 에너지 크기 + arr[i][0] = s; + arr[i][1] = l; + } + + K = Integer.parseInt(br.readLine()); + + dfs(1, false, 0); + System.out.println(min); + } + private static void dfs(int cnt, boolean bigJump, int E) { + if(cnt == N) { + min = Math.min(min, E); + return; + } + if(cnt > N) return; + // 작은 점프 + dfs(cnt+1, bigJump, E + arr[cnt][0]); + // 큰 점프 + dfs(cnt+2, bigJump, E + arr[cnt][1]); + // 완전 큰 점프 + if(!bigJump) dfs(cnt+3, true, E + K); + } +} \ No newline at end of file diff --git "a/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..8aa6b55 --- /dev/null +++ "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,5 @@ +package 문자열; + +public class Main_백준_17609_회문_골드5_함소연 { + +} diff --git "a/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_19583_\354\213\270\354\235\264\353\262\204\352\260\234\352\260\225\354\264\235\355\232\214_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_616ms.java" "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_19583_\354\213\270\354\235\264\353\262\204\352\260\234\352\260\225\354\264\235\355\232\214_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_616ms.java" new file mode 100644 index 0000000..5cc377f --- /dev/null +++ "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_19583_\354\213\270\354\235\264\353\262\204\352\260\234\352\260\225\354\264\235\355\232\214_\354\213\244\353\262\2042_\355\225\250\354\206\214\354\227\260_616ms.java" @@ -0,0 +1,60 @@ +package 문자열; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.StringTokenizer; + +public class Main_백준_19583_싸이버개강총회_실버2_함소연_616ms { + static HashMap map; + static int check = 0; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + String start = st.nextToken(); + String finish = st.nextToken(); + String end = st.nextToken(); + int[] startArr = splitTime(start); + int[] finishArr = splitTime(finish); + int[] endArr = splitTime(end); + map = new HashMap(); + + String input = ""; + while ((input = br.readLine()) != null && input.length() > 0) { + st = new StringTokenizer(input, " "); + String time = st.nextToken(); + String nickname = st.nextToken(); + int[] userArr = splitTime(time); + // 개강 총회 시작 전 ~ 시작 직전까지 + if((startArr[0] > userArr[0]) || (startArr[0] == userArr[0] && startArr[1] >= userArr[1])) { + map.put(nickname, false); + } + // 개강 총회 종료 후 ~ 스트리밍 종료 직전까지 + if((finishArr[0] == userArr[0] && finishArr[1] <= userArr[1]) || (finishArr[0] < userArr[0])) { + if((endArr[0] > userArr[0]) || (endArr[0] == userArr[0] && endArr[1] >= userArr[1])) { + if(map.containsKey(nickname) && !map.get(nickname)) { + map.put(nickname, true); + check++; + } + } + } + } + System.out.println(check); + } // end of main + + /** 시간 문자열 배열 -> 시간 정수형 배열 */ + private static int[] splitTime(String str) { + String[] arr = str.split(":"); + + int[] res = new int[2]; + for (int i = 0; i < 2; i++) { + res[i] = Integer.parseInt(arr[i]); + } + + return res; + } + +} // end of class diff --git "a/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_10815_\354\210\253\354\236\220\354\271\264\353\223\234_\354\213\244\353\262\2045_\355\225\250\354\206\214\354\227\260_1016ms.java" "b/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_10815_\354\210\253\354\236\220\354\271\264\353\223\234_\354\213\244\353\262\2045_\355\225\250\354\206\214\354\227\260_1016ms.java" new file mode 100644 index 0000000..d23414e --- /dev/null +++ "b/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_10815_\354\210\253\354\236\220\354\271\264\353\223\234_\354\213\244\353\262\2045_\355\225\250\354\206\214\354\227\260_1016ms.java" @@ -0,0 +1,52 @@ +package 이분탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_10815_숫자카드_실버5_함소연_1016ms { + public static int[] cards; + public static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); // 상근이가 가진 카드 수 + + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + cards = new int[N]; + for (int i = 0; i < N; i++) { + cards[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(cards); // 오름차순 정렬 + + int M = Integer.parseInt(br.readLine()); // 구해야 할 카드 수 + st = new StringTokenizer(br.readLine(), " "); + for (int i = 0; i < M; i++) { + int find = Integer.parseInt(st.nextToken()); + BinarySearch(find); + } + System.out.println(sb.toString()); + } + + private static void BinarySearch(int find) { + int start = 0, end = cards.length - 1, mid = end / 2; + + while (start <= end) { + mid = start + (end - start)/2; + if (cards[mid] == find) { // 카드를 찾으면 return; + sb.append(1 + " "); + return; + } + else if (cards[mid] < find) { // 찾으려는 카드가 오른쪽에 있다면 + start = mid + 1; + + }else { + end = mid - 1; + } + } + sb.append(0+" "); + } +} diff --git "a/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" "b/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..70092dd --- /dev/null +++ "b/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,61 @@ +package 이분탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_2110_공유기설치_골드4_함소연 { + private static int[] arr; + private static int N; + private static int C; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + N = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + + arr = new int[N]; + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(br.readLine()); + } + + Arrays.sort(arr); +// System.out.println(Arrays.toString(arr)); + BinarySearch(); + } + + private static void BinarySearch() { + int start = 0; + int end = N; + int cnt = 0; + int ans = 0; + while(start <= end) { + int mid = (start + end) / 2; + + // mid 거리 일 때 공유기 개수 구하기 + cnt = 1; // 처음 집부터 + int prev = arr[0]; + for (int i = 1; i < N; i++) { + int now = arr[i]; + if(now - prev >= mid) { + cnt++; + prev = now; + } + } +// System.out.println(start + " " + mid+" "+end); + + // 공유기 개수보다 작으면 + if(cnt < C) { + end = mid - 1; + }else { // 같거나 크면 + ans = mid; + start = mid + 1; + } + } + System.out.println(ans); + } +} diff --git "a/\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1374_\352\260\225\354\235\230\354\213\244_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_632ms.java" "b/\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1374_\352\260\225\354\235\230\354\213\244_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_632ms.java" new file mode 100644 index 0000000..af5b23f --- /dev/null +++ "b/\354\240\225\353\240\254/Main_\353\260\261\354\244\200_1374_\352\260\225\354\235\230\354\213\244_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_632ms.java" @@ -0,0 +1,64 @@ +package 정렬; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main_백준_1374_강의실_골드5_함소연_632ms { + static class Lecture implements Comparable{ + int idx; + int start; + int end; + public Lecture(int idx, int start, int end) { + super(); + this.idx = idx; + this.start = start; + this.end = end; + } + @Override + public int compareTo(Lecture o) { + if(this.start != o.start) { // 시작 시간이 빠른 순으로 정렬 + return this.start - o.start; + }else { // 시작시간이 같으면 종료시간이 빠른 순으로 정렬 + return this.end - o.end; + } + } + } + static int room = 0; + private static PriorityQueue pq; + private static Lecture[] lectures; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); // 강의 개수 + + pq = new PriorityQueue(); // 강의실 수 + + lectures = new Lecture[N]; + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + int idx = Integer.parseInt(st.nextToken()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + + lectures[i] = new Lecture(idx, start, end); + } + + Arrays.sort(lectures); // 강의 시간이 빠른 순으로 정렬 + + pq.offer(lectures[0].end); // 가장 먼저 시작하는 강의 offer + + for (int i = 1; i < N; i++) { +// System.out.println(pq); + if(lectures[i].start >= pq.peek()) { // 강의실 사용 가능할 경우 갱신 + pq.poll(); + } + pq.offer(lectures[i].end); + } + + System.out.println(pq.size()); + } +} From 764dbb8d6eacd51962852091513b39335603e764 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 14 Mar 2023 20:26:06 +0900 Subject: [PATCH 23/30] =?UTF-8?q?3=EC=9B=942=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\250\354\206\214\354\227\260.java" | 5 -- ...25\250\354\206\214\354\227\260_236ms.java" | 46 +++++++++++++++++++ ...25\250\354\206\214\354\227\260_284ms.java" | 10 ++-- 3 files changed, 50 insertions(+), 11 deletions(-) delete mode 100644 "\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_236ms.java" rename "\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" => "\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_284ms.java" (87%) diff --git "a/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" deleted file mode 100644 index 8aa6b55..0000000 --- "a/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260.java" +++ /dev/null @@ -1,5 +0,0 @@ -package 문자열; - -public class Main_백준_17609_회문_골드5_함소연 { - -} diff --git "a/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_236ms.java" "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_236ms.java" new file mode 100644 index 0000000..f314922 --- /dev/null +++ "b/\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17609_\355\232\214\353\254\270_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_236ms.java" @@ -0,0 +1,46 @@ +package 문자열; + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main_백준_17609_회문_골드5_함소연_236ms { + public static StringBuilder sb = new StringBuilder(); + public static int min = 3; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + for (int i = 0; i < N; i++) { + char[] ch = br.readLine().toCharArray(); + min = 3; + find(ch, 0, ch.length-1, 0); + sb.append(min).append("\n"); + } + System.out.println(sb.toString()); + } + + private static void find(char[] ch, int s, int e, int p) { + int C = ch.length/2; // 글자 개수 / 2 + if(ch.length%2 == 1) // 홀수 + C += 1; + if(s >= e) { + min = Math.min(min, p); + return; + } + // 회문 + if(ch[s] == ch[e]) { + find(ch, s+1, e-1, p); + } + // 유사 회문 + else if(ch[s] != ch[e] && p == 0) { + // 1. 왼쪽을 오른쪽으로 + find(ch, s+1, e, p+1); + // 2. 오른쪽을 왼쪽으로 + find(ch, s, e-1, p+1); + }else { + min = Math.min(min, p + 1); + return; + } + } +} diff --git "a/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" "b/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_284ms.java" similarity index 87% rename from "\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" rename to "\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_284ms.java" index 70092dd..6ab553e 100644 --- "a/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" +++ "b/\354\235\264\353\266\204\355\203\220\354\203\211/Main_\353\260\261\354\244\200_2110_\352\263\265\354\234\240\352\270\260\354\204\244\354\271\230_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_284ms.java" @@ -1,12 +1,11 @@ package 이분탐색; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; -public class Main_백준_2110_공유기설치_골드4_함소연 { +public class Main_백준_2110_공유기설치_골드4_함소연_284ms{ private static int[] arr; private static int N; private static int C; @@ -24,13 +23,13 @@ public static void main(String[] args) throws IOException { } Arrays.sort(arr); -// System.out.println(Arrays.toString(arr)); BinarySearch(); } private static void BinarySearch() { int start = 0; - int end = N; + int end = arr[N-1]; + int cnt = 0; int ans = 0; while(start <= end) { @@ -46,7 +45,6 @@ private static void BinarySearch() { prev = now; } } -// System.out.println(start + " " + mid+" "+end); // 공유기 개수보다 작으면 if(cnt < C) { @@ -58,4 +56,4 @@ private static void BinarySearch() { } System.out.println(ans); } -} +} \ No newline at end of file From 941d0a27326c5a460b3da83b3108bec38e3dc87c Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 28 Mar 2023 00:15:24 +0900 Subject: [PATCH 24/30] =?UTF-8?q?3=EC=9B=94=205=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\250\354\206\214\354\227\260_124ms.java" | 2 + ...25\250\354\206\214\354\227\260_168ms.java" | 239 ++++++++++++++++ ...25\250\354\206\214\354\227\260_440ms.java" | 253 +++++++++++++++++ ...25\250\354\206\214\354\227\260_428ms.java" | 261 ++++++++++++++++++ ...225\250\354\206\214\354\227\260_80ms.java" | 141 ++++++++++ 5 files changed, 896 insertions(+) create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21609_\354\203\201\354\226\264\354\244\221\355\225\231\352\265\220_\352\263\250\353\223\2342_\355\225\250\354\206\214\354\227\260_168ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21611_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\270\224\353\246\254\354\236\220\353\223\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_440ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_23290_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\263\265\354\240\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_428ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_3190_\353\261\200_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_80ms.java" diff --git "a/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" "b/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" index 9edb884..369dffc 100644 --- "a/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" +++ "b/DP/Main_\353\260\261\354\244\200_1106_\355\230\270\355\205\224_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_124ms.java" @@ -3,6 +3,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.Arrays; import java.util.StringTokenizer; /** knapsack */ @@ -32,6 +33,7 @@ public static void main(String[] args) throws IOException { } } + System.out.println(Arrays.toString(dp)); for (int i = 1; i <= 100001; i++) { if(dp[i] >= C) { // 적어도 C명 이상 고객 유치 System.out.println(i); diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21609_\354\203\201\354\226\264\354\244\221\355\225\231\352\265\220_\352\263\250\353\223\2342_\355\225\250\354\206\214\354\227\260_168ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21609_\354\203\201\354\226\264\354\244\221\355\225\231\352\265\220_\352\263\250\353\223\2342_\355\225\250\354\206\214\354\227\260_168ms.java" new file mode 100644 index 0000000..04f7d36 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21609_\354\203\201\354\226\264\354\244\221\355\225\231\352\265\220_\352\263\250\353\223\2342_\355\225\250\354\206\214\354\227\260_168ms.java" @@ -0,0 +1,239 @@ +package 코테기출; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_21609_상어중학교_골드2_함소연_168ms { + static class Pos implements Comparable { + int r; + int c; + int cnt; + int rainbow; + + public Pos(int r, int c, int cnt, int rainbow) { + super(); + this.r = r; + this.c = c; + this.cnt = cnt; + this.rainbow = rainbow; + } + + @Override + public int compareTo(Pos o) { + if (this.cnt == o.cnt) { + if (this.rainbow == o.rainbow) { + if (this.r == o.r) { + return o.c - this.c; + } else { + return o.r - this.r; + } + } else { + return o.rainbow - this.rainbow; + } + } else { + return o.cnt - this.cnt; + } + } + } + + private static int N; + private static int M; + private static int[][] map; + private static int score = 0; + private static boolean[][] isVisited; + private static int[] dr = { 0, 0, -1, 1 }; + private static int[] dc = { 1, -1, 0, 0 }; + + public static void main(String[] args) throws IOException { + input(); + go(); + System.out.println(score); + } + + private static void go() { + while (!checkBlock()) { // + Pos p = findBlock(); + if(p.cnt== 0) break; + remove(p); + gravity(); + turn(); + gravity(); + } + } + + private static void turn() { + int[][] temp = new int[N][N]; + + for (int i = N - 1; i >= 0; i--) { + for (int j = 0; j < N; j++) { + temp[N - i - 1][j] = map[j][i]; + } + } + + map = temp; + } + + private static void gravity() { + for (int i = 0; i < N; i++) { + int cnt = 0; + for (int j = N-1; j >= 0; j--) { + if(map[j][i] == -2) { + cnt++; + }else { + if(map[j][i] != -1 && cnt > 0) { + map[j + cnt][i] = map[j][i]; + map[j][i] = -2; + j = j + cnt; + cnt = 0; + }else { + cnt = 0; + } + } + } + } + } + + private static void remove(Pos b) { + Deque queue = new ArrayDeque(); + isVisited = new boolean[N][N]; + + isVisited[b.r][b.c] = true; + + queue.offer(new Pos(b.r, b.c, 0, 0)); + int color = map[b.r][b.c]; + + while (queue.size() > 0) { + Pos p = queue.poll(); + for (int d = 0; d < 4; d++) { + int nr = p.r + dr[d]; + int nc = p.c + dc[d]; + + if (nr < 0 || nr >= N || nc < 0 || nc >= N) + continue; + + if (map[nr][nc] == color && !isVisited[nr][nc]) { // 색이 같고 방문한 적이 없음 + isVisited[nr][nc] = true; + map[nr][nc] = -2; // 쓰레기 값 + queue.offer(new Pos(nr, nc, 0, 0)); + } else if (map[nr][nc] == 0 && !isVisited[nr][nc]) { // 무지개고, 방문한 적이 없음 + isVisited[nr][nc] = true; + map[nr][nc] = -2; // 쓰레기 값 + queue.offer(new Pos(nr, nc, 0, 0)); + } + } + + } // end of while + map[b.r][b.c] = -2; // 쓰레기 값 + score += b.cnt * b.cnt; + } + + private static Pos findBlock() { + Deque queue = new ArrayDeque(); + isVisited = new boolean[N][N]; + ArrayList list = new ArrayList(); + int color = 0; + int r = 0; + int c = 0; + int cnt = 0; + int rainbow = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + // 방문했었거나, 검은블록이거나, 무지개블록, 빈칸이면 continue + if (map[i][j] == 0 || map[i][j] == -1 || isVisited[i][j] || map[i][j] == -2) + continue; + + color = map[i][j]; + r = i; + c = j; + cnt = 1; // 개수 + rainbow = 0; + isVisited[i][j] = true; + queue.offer(new Pos(r, c, 0, 0)); + // BFS 시작 + while (queue.size() > 0) { + Pos p = queue.poll(); + for (int d = 0; d < 4; d++) { + int nr = p.r + dr[d]; + int nc = p.c + dc[d]; + + if (nr < 0 || nr >= N || nc < 0 || nc >= N) + continue; + + if (map[nr][nc] == color && !isVisited[nr][nc]) { // 색이 같고 방문한 적이 없음 + isVisited[nr][nc] = true; + queue.offer(new Pos(nr, nc, cnt++, rainbow)); + } else if (map[nr][nc] == 0 && !isVisited[nr][nc]) { // 무지개고, 방문한 적이 없음 + isVisited[nr][nc] = true; + queue.offer(new Pos(nr, nc, cnt++, rainbow++)); + } + } + + } // end of while + // list에 저장 + if(cnt != 1) + list.add(new Pos(r, c, cnt, rainbow)); + + // 무지개 방문 초기화 + for (int x = 0; x < N; x++) { + for (int y = 0; y < N; y++) { + if (map[x][y] == 0 && isVisited[x][y]) { + isVisited[x][y] = false; + } + } + } + } + } // end of for + Collections.sort(list); + if(list.size() == 0) { + return new Pos(0, 0, 0, 0); + } + Pos result = list.get(0); + return result; + + } + + private static boolean checkBlock() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (map[i][j] >= 1 && map[i][j] <= M) + return false; + } + } + return true; + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + map = new int[N][N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + } + + private static void print(int[][] arr) { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (arr[i][j] == -2) { + System.out.printf("%2s", "■"); + } else + System.out.printf("%2d", arr[i][j]); + } + System.out.println(); + } + System.out.println(); + } +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21611_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\270\224\353\246\254\354\236\220\353\223\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_440ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21611_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\270\224\353\246\254\354\236\220\353\223\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_440ms.java" new file mode 100644 index 0000000..4a31b15 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_21611_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\270\224\353\246\254\354\236\220\353\223\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_440ms.java" @@ -0,0 +1,253 @@ +package 코테기출; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Stack; +import java.util.StringTokenizer; + +public class Main_백준_21611_마법사상어와블리자드_골드1_함소연_440ms { + private static int N; + private static int M; + private static int[][] map; + private static int[][] magic; + private static int sharkr; + private static int sharkc; + private static int[] dr = { -1, 1, 0, 0 }; + private static int[] dc = { 0, 0, -1, 1 }; + private static int time; + private static int[] boom; + static ArrayList list; + static ArrayList removeList; + static Stack stack; + private static int res = 0; + + public static void main(String[] args) throws IOException { + input(); + go(); + System.out.println(res); + } + + private static void go() { + time = 0; + while (time++ < M) { + // 블리자드 마법 수행 + blizard(); + // 1차원으로 맵 풀기 + makeList(); + // 구슬 폭발 + boom(); + // 구슬 변화 + changeMarble(); + // 2차원 맵 만들기 + makeMap(); + } + res(); + } + + private static void res() { + res += (boom[0]) + (boom[1] * 2) + (boom[2] * 3); + } + + private static void makeMap() { + while (stack.size() <= N * N - 1) { + stack.push(0); + } + map = new int[N][N]; + int time = N * 2 - 1; + int n = N - 1; + int turn = 1; + + int r = 0; + int c = N - 1; + int nr = 0; + int nc = 0; + // 첫번째 줄 + for (int i = 0; i < N; i++) { + map[0][i] = stack.pop(); + } + // N * 2 - 1번 + while (time-- > 0) { + // 세로 + for (int i = 0; i < n; i++) { + r = r + turn; + map[r][c] = stack.pop(); + + } + + // 증가 <-> 감소 + turn = turn == 1 ? -1 : 1; + + // 가로 + for (int i = 0; i < n; i++) { + c = c + turn; + map[r][c] = stack.pop(); + } + + // 횟수 + n--; + } + } + + private static void changeMarble() { + stack = new Stack<>(); + stack.push(0); + for (int i = 0; i < list.size();) { + if (stack.size() > N * N - 1) + break; + int cnt = 1; + int marble = list.get(i); + if (i < list.size() - 1 && list.get(i) == list.get(i + 1)) { + for (int j = 1; j < 3; j++) { + if (i + j >= list.size() || list.get(i + j) != marble) { + break; + } + cnt++; + } + i += cnt; + } else { + i++; + } + stack.push(cnt); + stack.push(marble); + } + } + + private static void boom() { + while (!checkGroup()) { + int cnt = 1; + for (int i = 0; i < list.size() - 3; i++) { + cnt = 1; + if (list.size() == 0) + break; + if (list.get(i) != list.get(i + 1)) + continue; + int marble = list.get(i); + while (true) { + if (list.size() <= i + cnt) { + break; + } + if (marble == list.get(i + cnt)) { + cnt++; + } else + break; + } + if (cnt >= 4) { + for (int j = 0; j < cnt; j++) { + boom[marble - 1]++; + list.remove(i); + } + } + } + } + } + + private static boolean checkGroup() { + for (int i = 0; i < list.size() - 3; i++) { + if (list.get(i) != list.get(i + 1)) + continue; + int marble = list.get(i); + int cnt = 0; + for (int j = 0; j < 4; j++) { + if (marble != list.get(i + j)) { + // i += j; + break; + } else { + cnt++; + } + } + if (cnt == 4) { + return false; + } + } + return true; + } + + private static void makeList() { + list = new ArrayList<>(); + stack = new Stack<>(); + int time = N * 2 - 1; + int n = N - 1; + int turn = 1; + + int r = 0; + int c = N - 1; + int nr = 0; + int nc = 0; + // 첫번째 줄 + for (int i = 0; i < N; i++) { + stack.push(map[0][i]); + } + // N * 2 - 1번 + while (time-- > 0) { + // 세로 + for (int i = 0; i < n; i++) { + r = r + turn; + stack.push(map[r][c]); + + } + + // 증가 <-> 감소 + turn = turn == 1 ? -1 : 1; + + // 가로 + for (int i = 0; i < n; i++) { + c = c + turn; + stack.push(map[r][c]); + } + + // 횟 + n--; + } + while (!stack.isEmpty()) { + if (stack.peek() != 0) { + list.add(stack.pop()); + } else { + stack.pop(); + } + } + } + + private static void blizard() { + int d = magic[time - 1][0]; + int nr = sharkr; + int nc = sharkc; + for (int i = 0; i < magic[time - 1][1]; i++) { + nr += dr[d]; + nc += dc[d]; + if (nr < 0 || nr >= N || nc < 0 || nc >= N) + break; + map[nr][nc] = 0; + } + + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + map = new int[N][N]; // 맵 + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + magic = new int[M][2]; // 마법 + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine(), " "); + magic[i][0] = Integer.parseInt(st.nextToken()) - 1; + magic[i][1] = Integer.parseInt(st.nextToken()); + } + + sharkr = (N + 1) / 2 - 1; + sharkc = (N + 1) / 2 - 1; + + boom = new int[3]; + } + +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_23290_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\263\265\354\240\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_428ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_23290_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\263\265\354\240\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_428ms.java" new file mode 100644 index 0000000..328f23a --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_23290_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\353\263\265\354\240\234_\352\263\250\353\223\2341_\355\225\250\354\206\214\354\227\260_428ms.java" @@ -0,0 +1,261 @@ +package 코테기출; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + +public class Main_백준_23290_마법사상어와복제_골드1_함소연_428ms{ + static class Pos implements Comparable { + int cnt; + int p1; + int p2; + int p3; + + public Pos(int cnt, int p1, int p2, int p3) { + super(); + this.cnt = cnt; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + } + + @Override + public int compareTo(Pos o) { + if (this.cnt == o.cnt) { + if (this.p1 == o.p1) { + if (this.p2 == o.p2) { + return this.p3 - o.p3; + } else + return this.p2 - o.p2; + } else + return this.p1 - o.p1; + } else + return o.cnt - this.cnt; + } + } + + private static int[] sr = { -1, 0, 1, 0 }; // 상 좌 하 우 + private static int[] sc = { 0, -1, 0, 1 }; + private static int[] dr = { 0, -1, -1, -1, 0, 1, 1, 1 }; // 물고기 방향 + private static int[] dc = { -1, -1, 0, 1, 1, 1, 0, -1 }; + private static int S; + private static int M; + private static ArrayList[][] map; + private static ArrayList[][] temp; + private static ArrayList[][] copy; + private static ArrayList list; + private static int[][] smell; + private static boolean[][] isVisited; + private static int[] move; + private static int sharkr; + private static int sharkc; + private static int maxCnt = -1; + + public static void main(String[] args) throws IOException { + input(); + go(); + int res = 0; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if (!map[i][j].isEmpty()) { + for (int k = 0; k < map[i][j].size(); k++) { + res++; + } + } + } + } + System.out.println(res); + } + + private static void go() { + while (S-- > 0) { + // 물고기 복제 + copyOfFish(); + // 물고기 한칸 이동 + moveFish(); + // 상어 3칸이동 + moveShark(); + // 2턴 전 물고기 냄새 삭제 + removeSmell(); + // 복제 마법 완료 + completeCopy(); + map = temp; + } + } + + private static void removeSmell() { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if(smell[i][j] < -2) { + smell[i][j] = 0; + } + } + } + } + + private static void completeCopy() { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if (!copy[i][j].isEmpty()) { + for (int k = 0; k < copy[i][j].size(); k++) { + temp[i][j].add(copy[i][j].get(k)); + } + } + } + } + + } + + private static void moveShark() { + move = new int[3]; + list = new ArrayList<>(); + maxCnt = -1; + // 중복 순열 + + perm(0); + + Collections.sort(list); + Pos p = list.get(0); // 최대 개수 구하기 + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if(smell[i][j] != 0) { + smell[i][j]--; + } + } + } + // 물고기 지우기 + int r = sharkr; + int c = sharkc; + int[] pos = { p.p1, p.p2, p.p3 }; + for (int i = 0; i < 3; i++) { + int nr = r + sr[pos[i]]; + int nc = c + sc[pos[i]]; + if (nr < 0 || nr >= 4 || nc < 0 || nc >= 4) + continue; + if (!temp[nr][nc].isEmpty()) { + temp[nr][nc].clear(); + smell[nr][nc] = -1; + } + r = nr; + c = nc; + } + sharkr = r; + sharkc = c; + } + + private static void perm(int start) { + if (start == 3) { + checkCnt(move); + return; + } + for (int i = 0; i < 4; i++) { + move[start] = i; + perm(start + 1); + } + } + + private static void checkCnt(int[] move) { + isVisited = new boolean[4][4]; + int cnt = 0; + int r = sharkr; + int c = sharkc; + for (int i = 0; i < 3; i++) { + + int nr = r + sr[move[i]]; + int nc = c + sc[move[i]]; + if (nr < 0 || nr >= 4 || nc < 0 || nc >= 4) + return; + if (!temp[nr][nc].isEmpty() && !isVisited[nr][nc]) { + isVisited[nr][nc] = true; + cnt += temp[nr][nc].size(); + } + r = nr; + c = nc; + } + if(maxCnt < cnt) { + maxCnt = cnt; + list.add(new Pos(cnt, move[0], move[1], move[2])); + } + } + + private static boolean checkMoveFish(int nr, int nc) { + if (nr < 0 || nr >= 4 || nc < 0 || nc >= 4 || smell[nr][nc] < 0 || (nr == sharkr && nc == sharkc)) + return false; + else + return true; + } + + private static void moveFish() { + for (int r = 0; r < 4; r++) { + for (int c = 0; c < 4; c++) { + if (map[r][c].isEmpty()) + continue; + for (int k = 0; k < map[r][c].size(); k++) { + int d = (int) map[r][c].get(k); // 바로 이동 + // 장애물 O + if (!checkMoveFish(r + dr[d], c + dc[d])) { + int cnt = 8; + while (cnt-- > 0) { + d--; + if (d < 0) { + d = 7; + } + if (checkMoveFish(r + dr[d], c + dc[d])) { + temp[r + dr[d]][c + dc[d]].add(d); // 자리 이동 + break; + } + } + if ((int) map[r][c].get(k) == d) { // 움직일 수 없음. + temp[r][c].add(d); + } + } + // 장애물 X + else { + temp[r + dr[d]][c + dc[d]].add(d); // 자리 이동 + } + } + } + } + } + + private static void copyOfFish() { + temp = new ArrayList[4][4]; + copy = new ArrayList[4][4]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + temp[i][j] = new ArrayList<>(); + copy[i][j] = new ArrayList<>(); + } + } + copy = map; + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + M = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + map = new ArrayList[4][4]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + map[i][j] = new ArrayList(); + } + } + smell = new int[4][4]; + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine(), " "); + int r = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + int d = Integer.parseInt(st.nextToken()); + + map[r - 1][c - 1].add(d - 1); + } + st = new StringTokenizer(br.readLine(), " "); + sharkr = Integer.parseInt(st.nextToken()) - 1; + sharkc = Integer.parseInt(st.nextToken()) - 1; + } +} \ No newline at end of file diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_3190_\353\261\200_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_80ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_3190_\353\261\200_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_80ms.java" new file mode 100644 index 0000000..ea3b126 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\234/Main_\353\260\261\354\244\200_3190_\353\261\200_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_80ms.java" @@ -0,0 +1,141 @@ +package 코테기출; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.StringTokenizer; + +public class Main_백준_3190_뱀_골드4_함소연_80ms { + static class Pos { + int r; + int c; + + public Pos(int r, int c) { + this.r = r; + this.c = c; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + private static Deque queue = new ArrayDeque(); + private static ArrayList list = new ArrayList(); + private static int N; + private static int L; + private static int K; + private static int[][] map; + private static int[][] turn; + private static int time = 0; + private static int[] dr = { 0, 1, 0, -1 }; // 우 하 좌 상 + private static int[] dc = { 1, 0, -1, 0 }; + private static int d = 0; + private static int idx = 0; + private static int[][] temp; + + public static void main(String[] args) throws NumberFormatException, IOException { + input(); + go(); + System.out.println(sb.toString()); + } + + private static void go() { + int r = 0; + int c = 0; + queue.offer(new Pos(0, 0)); + map[0][0] = 1; + while (true) { + // 직진 + int nr = r + dr[d]; // 한칸 이동 + int nc = c + dc[d]; + + // 시간 증가 + time++; + + // 움직일 수 있는지 확인 + // 없으면 break; + if (!isPossible(nr, nc)) + break; + + // 머리에 사과 확인 + if (!isApple(nr, nc)) { // 사과가 없으면, queue.poll + Pos p = queue.poll(); + map[p.r][p.c] = 0; // 꼬리 삭제 + } + + // 머리를 다음칸에 위치 queue.offer() + queue.offer(new Pos(nr, nc)); + map[nr][nc] = 1; // 머리 + + // 방향확인 + checkDirection(); + + // head 재지정 + r = nr; + c = nc; + } + sb.append(time); + } + + private static void checkDirection() { + int key = 0; + + if (idx < L && turn[idx][0] == time) { + key = turn[idx][1]; + idx++; + } + if (key == 'L') { // 왼쪽 + d--; + if (d < 0) + d = 3; // 범위 재지정 + } else if (key == 'D') { // 오른쪽 + d++; + if (d > 3) + d = 0; // 범위 재지정 + } + } + + private static boolean isPossible(int r, int c) { + // 벽 + if (r < 0 || r >= N || c < 0 || c >= N) { + return false; + } + // 자기 몸 + if (map[r][c] == 1) + return false; + return true; + } + + private static boolean isApple(int r, int c) { + if (map[r][c] == 2) { + return true; + } else + return false; + } + + private static void input() throws NumberFormatException, IOException { + N = Integer.parseInt(br.readLine()); + map = new int[N][N]; + + K = Integer.parseInt(br.readLine()); + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine(), " "); + int r = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + map[r - 1][c - 1] = 2; // apple + } + + L = Integer.parseInt(br.readLine()); + turn = new int[L][2]; + for (int i = 0; i < L; i++) { + st = new StringTokenizer(br.readLine(), " "); + int x = Integer.parseInt(st.nextToken()); + int c = st.nextToken().charAt(0); + turn[i][0] = x; + turn[i][1] = c; + } + } +} From 9a3a8cf51d061ef20eb591bdf246fd7d4013f1e8 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 28 Mar 2023 19:51:51 +0900 Subject: [PATCH 25/30] =?UTF-8?q?3=EC=9B=94=205=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\250\354\206\214\354\227\260.java" | 33 ++++++++++++++++ ...\355\225\250\354\206\214\354\227\260.java" | 39 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\203\235\353\260\260\353\260\260\353\213\254\352\263\274\354\210\230\352\261\260\355\225\230\352\270\260_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\214\214\352\264\264\353\220\230\354\247\200\354\225\212\354\235\200\352\261\264\353\254\274_\355\225\250\354\206\214\354\227\260.java" diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\203\235\353\260\260\353\260\260\353\213\254\352\263\274\354\210\230\352\261\260\355\225\230\352\270\260_\355\225\250\354\206\214\354\227\260.java" "b/\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\203\235\353\260\260\353\260\260\353\213\254\352\263\274\354\210\230\352\261\260\355\225\230\352\270\260_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..0aee2bb --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\203\235\353\260\260\353\260\260\353\213\254\352\263\274\354\210\230\352\261\260\355\225\230\352\270\260_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,33 @@ +package 코테기출; + +public class Solution_Programmers_택배배달과수거하기_함소연 { + class Solution { + public long solution(int cap, int n, int[] deliveries, int[] pickups) { + // 맨 끝집부터 차례대로 가져갈 수 있는 택배상자 수 확인 + // 차례대로 수거할 수 있는 상자 확인 + int d = 0; + int p = 0; + long distance = 0; + long answer = 0; + int cnt = 1; + for (int i = n-1; i >= 0; i--) { + if(deliveries[i] == 0 && pickups[i] == 0) { + continue; + } + d -= deliveries[i]; + p -= pickups[i]; + cnt = 0; + while(d < 0 || p < 0) { + d += cap; + p += cap; + cnt++; + } + + distance += cnt * (i+1) * 2; + } + answer = distance; + return answer; + } + } + +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\214\214\352\264\264\353\220\230\354\247\200\354\225\212\354\235\200\352\261\264\353\254\274_\355\225\250\354\206\214\354\227\260.java" "b/\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\214\214\352\264\264\353\220\230\354\247\200\354\225\212\354\235\200\352\261\264\353\254\274_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..e030cdd --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\234/Solution_Programmers_\355\214\214\352\264\264\353\220\230\354\247\200\354\225\212\354\235\200\352\261\264\353\254\274_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,39 @@ +package 코테기출; + +public class Solution_Programmers_파괴되지않은건물_함소연 { + class Solution { + public int solution(int[][] board, int[][] skill) { + int mcnt = 0; + int N = board.length * board[0].length; + for (int k = 0; k < skill.length; k++) { + int type = skill[k][0]; + + int r1 = skill[k][1]; + int c1 = skill[k][2]; + int r2 = skill[k][3]; + int c2 = skill[k][4]; + + int degree = skill[k][5]; + if(type == 1) { + degree *= -1; + } + for (int i = r1; i <= r2; i++) { + for (int j = c1; j <= c2; j++) { + boolean flag = false; + if(board[i][j] <= 0) { // 파괴 + flag = true; + } + board[i][j] += degree; + if(board[i][j] <= 0 && !flag) { // 파괴 + mcnt--; + }else if(board[i][j] > 0 && flag) { + mcnt++; + } + } + } + } + System.out.println(N); + return N + mcnt; + } + } +} From f55c2c91d6f7deecadf353e30bd9f756783b55eb Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 4 Apr 2023 01:30:46 +0900 Subject: [PATCH 26/30] =?UTF-8?q?4=EC=9B=94=201=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\235\264_\352\263\250\353\223\2342.java" | 122 +++++++++++++ ...25\250\354\206\214\354\227\260_544ms.java" | 159 +++++++++++++++++ ...25\250\354\206\214\354\227\260_452ms.java" | 158 +++++++++++++++++ ...\260_\352\263\250\353\223\2343_456ms.java" | 160 ++++++++++++++++++ 4 files changed, 599 insertions(+) create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_17825_\354\243\274\354\202\254\354\234\204\354\234\267\353\206\200\354\235\264_\352\263\250\353\223\2342.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20056_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\353\263\274_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_544ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20057_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\206\240\353\204\244\354\235\264\353\217\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_452ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20058_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\354\212\244\355\206\260_\352\263\250\353\223\2343_456ms.java" diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_17825_\354\243\274\354\202\254\354\234\204\354\234\267\353\206\200\354\235\264_\352\263\250\353\223\2342.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_17825_\354\243\274\354\202\254\354\234\204\354\234\267\353\206\200\354\235\264_\352\263\250\353\223\2342.java" new file mode 100644 index 0000000..9df7e3e --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_17825_\354\243\274\354\202\254\354\234\204\354\234\267\353\206\200\354\235\264_\352\263\250\353\223\2342.java" @@ -0,0 +1,122 @@ +package 코테기출2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_17825_주사위윷놀이_골드2 { + private static int ans = 0; + private static int[] dice; + private static int[] arr; + private static int[][] map = { + {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 0}, + {10, 13, 16, 19}, + {20, 22, 24}, + {30, 28, 27, 26}, + {25, 30, 35, 40, 0}}; + static class Node{ + int score; + int idx; + int m; + public Node(int score, int idx, int m) { + this.score = score; + this.idx = idx; + this.m = m; + } + } + + public static void main(String[] args) throws IOException { + input(); + go(); + System.out.println(ans); + } + + + private static void go() { + gerPlayer(0); + } + + private static void roll(int[] arr) { + Node[] node = new Node[4]; + for (int i = 0; i < node.length; i++) { + node[i] = new Node(0, 0, 0); + } + for(int t = 0; t < 10; t++) { + int player = arr[t]; // 현재 플레이어 + if(node[player].idx == 0 || node[player].idx == 4) { + if(node[player].m + dice[t] >= map[node[player].idx].length) { // 범위 초과 시 재조정 + node[player].m = map[node[player].idx].length-1; + continue; + }else { + node[player].m += dice[t]; + } + }else { + if(node[player].m + dice[t] >= map[node[player].idx].length) { // 범위 초과 시 재조정 + node[player].m = node[player].m + dice[t] - map[node[player].idx].length; + node[player].idx = 4; + }else { + node[player].m += dice[t]; + } + } + int score = map[node[player].idx][node[player].m]; // 이동한 말판의 점수 + if(node[player].idx == 0) { + switch (score) { + case 10: + node[player].idx = 1; + node[player].m = 0; + break; + case 20: + node[player].idx = 2; + node[player].m = 0; + break; + case 30: + node[player].idx = 3; + node[player].m = 0; + break; + default: + break; + } + } + // 말 이동을 마치는 칸에 다른 말이 있으면 고를 수 없다. + for (int i = 0; i < 4; i++) { + if(i == player) continue; + // 25 30 35 40 체크 + if(node[i].idx == node[player].idx && node[i].m == node[player].m) { + return; + } + if(map[node[i].idx][node[i].m] == score && score == 40) { + return; + } + } + node[player].score += score; + + } + int sum = 0; + for (int i = 0; i < 4; i++) { + sum += node[i].score; + } + ans = Math.max(ans, sum); + } + + private static void gerPlayer(int start) { + if(start == 10) { + roll(arr); + return; + } + for (int i = 0; i < 4; i++) { + arr[start] = i; + gerPlayer(start+1); + } + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + dice = new int[10]; + for (int i = 0; i < 10; i++) { + dice[i] = Integer.parseInt(st.nextToken()); + } + arr = new int[10]; + } +} \ No newline at end of file diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20056_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\353\263\274_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_544ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20056_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\353\263\274_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_544ms.java" new file mode 100644 index 0000000..4dc1e62 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20056_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\353\263\274_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260_544ms.java" @@ -0,0 +1,159 @@ +package 코테기출2; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_20056_마법사상어와파이어볼_골드4_함소연_544ms{ + static class Pos { + int m; + int s; + int d; + + public Pos(int m, int s, int d) { + this.m = m; + this.s = s; + this.d = d; + } + } + + private static int ans = 0; + private static int K; + private static int N; + private static ArrayList[][] list; + private static int[] dr = { -1, -1, 0, 1, 1, 1, 0, -1 }; + private static int[] dc = { 0, 1, 1, 1, 0, -1, -1, -1 }; + + public static void main(String[] args) throws IOException { + input(); + go(); + } // end of main + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + list = new ArrayList[N][N]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + list[i][j] = new ArrayList(); + } + } + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine(), " "); + int r = Integer.parseInt(st.nextToken()) - 1; + int c = Integer.parseInt(st.nextToken()) - 1; + int m = Integer.parseInt(st.nextToken()); // 질량 + int s = Integer.parseInt(st.nextToken()); // 속력 + int d = Integer.parseInt(st.nextToken()); // 방향 + list[r][c].add(new Pos(m, s, d)); + } + } + + private static void go() { + while (K-- > 0) { + move(); + sum(); + } + getAmount(); + } + + private static void getAmount() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (list[i][j].size() == 0) + continue; + for (int k = 0; k < list[i][j].size(); k++) { + ans += list[i][j].get(k).m; + } + } + } + System.out.println(ans); + } + + private static void sum() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + int size = list[i][j].size(); + if (size == 0 || size == 1) + continue; // 0개 , 1개 + // 2개 이상 + int mSum = 0; + int sSum = 0; + int cnt = size; + int dAll = 0; + boolean flag = false; // f : 0, 2, 4, 6 t : 1, 3, 5, 7 + for (int k = 0; k < size; k++) { + Pos p = list[i][j].get(k); + mSum += p.m; // 질량 + sSum += p.s; // 속력 + if (k == 0) { // 방향 + dAll = p.d % 2; + } else { + if (dAll != p.d % 2) { + flag = true; + } + } + } + list[i][j].clear(); + int m = mSum / 5; + if (m == 0) + continue; + int s = sSum / cnt; + if (!flag) { // f : 0, 2, 4, 6 t : 1, 3, 5, 7 + for (int k = 0; k < 8; k += 2) { + list[i][j].add(new Pos(m, s, k)); + } + } else { + for (int k = 1; k < 8; k += 2) { + list[i][j].add(new Pos(m, s, k)); + } + } + } + } + } + + private static void move() { + ArrayList temp = new ArrayList<>(); + // 이동 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + int size = list[i][j].size(); + if (size == 0) + continue; + for (int k = size - 1; k >= 0; k--) { + Pos p = list[i][j].get(k); + int nr = i + dr[p.d] * p.s; + int nc = j + dc[p.d] * p.s; + if (nr < 0) { + nr = nr % N; + if(nr != 0) { + nr += N; + } + } else if (nr >= N) { + nr = nr % N; + } + if (nc < 0) { + nc = nc % N; + if(nc != 0) { + nc += N; + } + } else if (nc >= N) { + nc = nc % N; + } + int[] a = { nr, nc, p.m, p.s, p.d }; + temp.add(a); + list[i][j].remove(k); // 초기화 + } + } + } + for (int i = 0; i < temp.size(); i++) { + list[temp.get(i)[0]][temp.get(i)[1]].add(new Pos(temp.get(i)[2], temp.get(i)[3], temp.get(i)[4])); + } + } +} // end of class diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20057_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\206\240\353\204\244\354\235\264\353\217\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_452ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20057_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\206\240\353\204\244\354\235\264\353\217\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_452ms.java" new file mode 100644 index 0000000..f16245e --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20057_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\206\240\353\204\244\354\235\264\353\217\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_452ms.java" @@ -0,0 +1,158 @@ +package 코테기출2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main_백준_20057_마법사상어와토네이도_골드3_함소연_452ms { + private static int[][] map; + private static int ans = 0; + private static int N; + private static int time; + private static int[] dr = {0, 1, 0, -1}; // 좌 하 우 상 + private static int[] dc = {-1, 0, 1, 0}; + private static int d = 1; + private static int cnt = 0; + private static int turn = 0; + private static int r; + private static int c; + public static void main(String[] args) throws NumberFormatException, IOException { + input(); + go(); + System.out.println(ans); + } // end of main + + private static void go() { + time = N*N; + r = N/2; + c = N/2; + while(time-- >0) { + move(); + } + } + + + private static void move() { +// System.out.println(r+" "+c); + int nr = r + dr[turn]; + int nc = c + dc[turn]; + if(nr == 0 && nc == -1) return; +// System.out.println(nr+" "+nc); + + if(map[nr][nc] != 0) { + tornado(nr, nc); + } + System.out.println("turn: "+turn +" d:"+d+" cnt:"+cnt); + print(nr, nc); + cnt++; + if( d == cnt ) { + cnt = 0; + turn++; + if(turn == 2) { + d++; + } + if(turn == 4) { + d++; + turn = 0; + } + } + map[r][c] = 0; + r = nr; c = nc; + } + + private static void print(int r, int c) { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if(i == r && j == c) { + System.out.print("■ "); + }else { + System.out.print(map[i][j]+" "); + } + } + System.out.println(); + } + } + + private static void tornado(int nr, int nc) { + int mr = 0 ; int mc = 0; + int amount = 0; + switch (turn) { + case 0: + // 1% + amount = (int) (map[nr][nc] * 0.01); + mr = nr + 1; + mc = nc + 1; + getAmount(amount, mr, mc); + mr = nr - 1; + mc = nc + 1; + getAmount(amount, mr, mc); + // 2% + amount = (int) (map[nr][nc] * 0.02); + mr = nr + 2; + mc = nc; + getAmount(amount, mr, mc); + mr = nr - 2; + mc = nc; + getAmount(amount, mr, mc); + // 5% + amount = (int) (map[nr][nc] * 0.05); + mr = nr; + mc = nc - 2; + getAmount(amount, mr, mc); + // 7% + amount = (int) (map[nr][nc] * 0.07); + mr = nr + 1; + mc = nc; + getAmount(amount, mr, mc); + mr = nr - 1; + mc = nc; + getAmount(amount, mr, mc); + // 10% + amount = (int) (map[nr][nc] * 0.1); + mr = nr - 1; + mc = nc - 1; + getAmount(amount, mr, mc); + mr = nr + 1; + mc = nc - 1; + getAmount(amount, mr, mc); + // a + amount = (int) (map[nr][nc] * 0.55); + mr = nr; + mc = nc - 1; + getAmount(amount, mr, mc); + break; + + default: + break; + } + + mr = nr + dr[turn]; + mc = nc + dc[turn]; + + + } + + + private static void getAmount(int amount, int mr, int mc) { + if(mr > 0 || mr <= N || mc > 0 || mc <= N ) { + ans += amount; + }else { + map[mr][mc] += amount; + } + } + + private static void input() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + map = new int[N][N]; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + } + +} // end of class diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20058_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\354\212\244\355\206\260_\352\263\250\353\223\2343_456ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20058_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\354\212\244\355\206\260_\352\263\250\353\223\2343_456ms.java" new file mode 100644 index 0000000..984a82f --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2342/Main_\353\260\261\354\244\200_20058_\353\247\210\353\262\225\354\202\254\354\203\201\354\226\264\354\231\200\355\214\214\354\235\264\354\226\264\354\212\244\355\206\260_\352\263\250\353\223\2343_456ms.java" @@ -0,0 +1,160 @@ +package 코테기출2; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_20058_마법사상어와파이어스톰_골드3_456ms{ + private static int N; + private static int Q; + private static int[][] map; + private static int[][] temp; + private static int[] arr; + private static int idx = 0; + private static int[] dr = { 0, 0, -1, 1 }; + private static int[] dc = { 1, -1, 0, 0 }; + private static int total; + private static boolean[][] isVisited; + private static int group; + private static int MAX = 0; + + public static void main(String[] args) throws IOException { + input(); + go(); + System.out.println(total); + System.out.println(MAX); + } + + private static void go() { + int time = Q; + while (time-- > 0) { + turn(); + temp = new int[N][N]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + temp[i][j] = map[i][j]; + } + } + removeIce(); + map=temp; + } + getCount(); + getGroup(); + } + + // 가장 큰 덩어리의 개수 구하기 dfs + private static void getGroup() { + isVisited = new boolean[N][N]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if(map[i][j] >= 1) { + group = 1; + isVisited[i][j] = true; + dfs(i, j); + MAX = Math.max(group, MAX); + } + } + } + } + + private static void dfs(int r, int c) { + for (int k = 0; k < 4; k++) { + int nr = r + dr[k]; + int nc = c + dc[k]; + if (nr < 0 || nr >= N || nc < 0 || nc >= N ) continue; + if(!isVisited[nr][nc] && map[nr][nc] >= 1) { + isVisited[nr][nc] = true; + group++; + dfs(nr, nc); + } + } + } + + // 남아있는 얼음 합 + private static void getCount() { + total = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (map[i][j] >= 1) { + total += map[i][j]; + } + } + } + } + + // 3이상과 인접해있지 않은 칸은 1감소 + private static void removeIce() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + int cnt = 0; + for (int k = 0; k < 4; k++) { + int nr = i + dr[k]; + int nc = j + dc[k]; + if (nr < 0 || nr >= N || nc < 0 || nc >= N || map[nr][nc] <= 0) { + cnt++; + } + } + if (cnt >= 2) { + temp[i][j] -= 1; + } + } + } + } + + // 시계방향 회전 + private static void turn() { + int L = arr[idx++]; + if(L == 0) return; + int size = (int) Math.pow(2, L); + for (int i = 0; i < N; i += size) { + for (int j = 0; j < N; j += size) { + int cnt = 0; + int r = i; + int c = j; + while (cnt < size / 2) { + int len = size - cnt * 2; + int[] temp = new int[len]; + for (int k = 0; k < len; k++) { + temp[k] = map[r][c + k]; + } + for (int k = 0; k < len; k++) { + map[r][c + k] = map[r + len - 1 - k][c]; + } + for (int k = 0; k < len; k++) { + map[r + k][c] = map[r + len - 1][c + k]; + } + for (int k = 0; k < len; k++) { + map[r + len - 1][c + k] = map[r + len - 1 - k][c + len - 1]; + } + for (int k = 0; k < len; k++) { + map[r + k][c + len - 1] = temp[k]; + } + r += 1; + c += 1; + cnt++; + } + } + } + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + Q = Integer.parseInt(st.nextToken()); + int size = (int) Math.pow(2, N); + N = size; + map = new int[N][N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + arr = new int[Q]; + st = new StringTokenizer(br.readLine(), " "); + for (int i = 0; i < Q; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + } +} From 84e490829805e93565777e78f1c9cae1cf69396d Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Mon, 17 Apr 2023 22:07:54 +0900 Subject: [PATCH 27/30] =?UTF-8?q?4=EC=9B=94=203=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\250\354\206\214\354\227\260_724ms.java" | 73 ++++++++ ...\355\225\250\354\206\214\354\227\260.java" | 172 ++++++++++++++++++ ...\355\225\250\354\206\214\354\227\260.java" | 51 ++++++ ...\355\225\250\354\210\230\354\227\260.java" | 37 ++++ ...25\250\354\206\214\354\227\260_268ms.java" | 76 ++++++++ ...\355\212\270\352\263\265\353\266\200.java" | 67 +++++++ 6 files changed, 476 insertions(+) create mode 100644 "\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_16934_\352\262\214\354\236\204\353\213\211\353\204\244\354\236\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_724ms.java" create mode 100644 "\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_1749_\354\240\220\354\210\230\353\224\260\353\250\271\352\270\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" create mode 100644 "\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_2015_\354\210\230\353\223\244\354\235\230\355\225\2514_\352\263\250\353\223\2344_\355\225\250\354\210\230\354\227\260.java" create mode 100644 "\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_20437_\353\254\270\354\236\220\354\227\264\352\262\214\354\236\2042_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_268ms.java" create mode 100644 "\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Solution_Programmers_\354\275\224\353\224\251\355\205\214\354\212\244\355\212\270\352\263\265\353\266\200.java" diff --git "a/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_16934_\352\262\214\354\236\204\353\213\211\353\204\244\354\236\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_724ms.java" "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_16934_\352\262\214\354\236\204\353\213\211\353\204\244\354\236\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_724ms.java" new file mode 100644 index 0000000..4d9e0d0 --- /dev/null +++ "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_16934_\352\262\214\354\236\204\353\213\211\353\204\244\354\236\204_\352\263\250\353\223\2343_\355\225\250\354\206\214\354\227\260_724ms.java" @@ -0,0 +1,73 @@ +package 기출_문자열; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class Main_백준_16934_게임닉네임_골드3_함소연_724ms { + static StringBuilder sb = new StringBuilder(); + static ArrayList list = new ArrayList(); + static Map check = new HashMap(); + static int N; + public static void main(String[] args) throws NumberFormatException, IOException { + input(); + System.out.println(sb.toString()); + } + private static void input() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + Trie trie = new Trie(); + String str = ""; + for (int i = 0; i < N; i++) { + str = br.readLine(); + if(check.get(str) == null) { + check.put(str, 1); + }else { + check.put(str, check.get(str) + 1); + sb.append(str+check.get(str)+"\n"); + continue; + } + trie.search(str); + list.forEach( c -> { sb.append(c);}); + sb.append("\n"); + trie.insert(str); + list.clear(); + } + } + static class Node{ + // 자식 노드 + Map childNodes = new HashMap(); + // 단어의 끝 체크 + boolean endWord; + } + + static class Trie{ + Node rootNode = new Node(); + + // 문자열 저장 + void insert(String str) { + Node node = this.rootNode; + for (int i = 0; i < str.length(); i++) { + node = node.childNodes.computeIfAbsent(str.charAt(i), key -> new Node()); + } + node.endWord = true; // 단어의 끝을 명시 + } + + boolean search(String str) { + Node node = this.rootNode; + for (int i = 0; i < str.length(); i++) { + node = node.childNodes.getOrDefault(str.charAt(i), null); + list.add(str.charAt(i)); + if(node == null) { + return false; + } + } + + return node.endWord; + } + } +} diff --git "a/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..6d70036 --- /dev/null +++ "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,172 @@ +package 기출_문자열; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Deque; +import java.util.List; +import java.util.StringTokenizer; + +public class Main_백준_17142_연구소3_골드4_함소연 { + static class Virus{ + int r, c, status; + + public Virus(int r, int c, int status) { + this.r = r; + this.c = c; + this.status = status; + } + + public Virus(int r, int c) { + this.r = r; + this.c = c; + } + + } + static int N, M, min; + static int[][] map; + static int[] dr = {0,0,-1,1}; + static int[] dc = {-1,1,0,0}; + static List virus; + static boolean[][] isVisited; + static boolean isLinked; + static int empty; + public static void main(String[] args) throws IOException { + input(); + go(); + System.out.println(min == Integer.MAX_VALUE ? -1 : min); + } + + private static void go() { + changeMap(); + if(virus.size() == 0) { + System.out.println(0); + System.exit(0); + } + if(virus.size() < M) + M = virus.size(); + comb(0, 0); + } + + private static void comb(int idx, int start) { + if (idx == M) { + spread(empty); + return; + } + + for (int i = start; i < virus.size(); i++) { + Virus v = virus.get(i); + virus.get(i).status = 0; + comb(idx+1, i+1); + virus.get(i).status = -1; + } + } + + private static void changeMap() { + Deque queue = new ArrayDeque(); + int[][] temp = new int[N][N]; + for (int i = 0; i < N; i++) { + temp[i] = Arrays.copyOf(map[i], N); + } + virus.forEach( vir -> { + if(map[vir.r][vir.c] == 2) { + isVisited = new boolean[N][N]; + queue.offer(new Virus(vir.r, vir.c)); + map[vir.r][vir.c] = 1; + isVisited[vir.r][vir.c] = true; + isLinked = true; + EX:while(queue.size() > 0) { + Virus v = queue.poll(); + int nr, nc; + for (int i = 0; i < 4; i++) { + nr = v.r + dr[i]; + nc = v.c + dc[i]; + + if(nr < 0 || nr >= N || nc < 0 || nc >= N || isVisited[nr][nc]) continue; + if(map[nr][nc] == 0) { + isLinked = false; + break EX; // 모두 바이러스가 아니면 탈출 + } + if(map[nr][nc] == 1) continue; + if(map[nr][nc] == 2) { + map[nr][nc] = 1; + isVisited[nr][nc] = true; + queue.offer(new Virus(nr, nc)); + } + } + } + if(!isLinked) { + for (int i = 0; i < N; i++) { + map[i] = Arrays.copyOf(temp[i], N); + } + }else { + for (int i = 0; i < N; i++) { + temp[i] = Arrays.copyOf(map[i], N); + } + } + } + }); + int size = virus.size(); + for (int i = size-1; i >= 0; i--) { + Virus v = virus.get(i); + if(map[v.r][v.c] == 1) + virus.remove(i); + } + } + + private static void spread(int empty) { + Deque queue = new ArrayDeque(); + isVisited = new boolean[N][N]; + virus.forEach( v -> { + if(v.status == 0) { + queue.offer(new Virus(v.r, v.c, v.status)); + isVisited[v.r][v.c] = true; + } + }); + while(queue.size() > 0) { + Virus v = queue.poll(); + int nr, nc; + for (int i = 0; i < 4; i++) { + nr = v.r + dr[i]; + nc = v.c + dc[i]; + + if(nr < 0 || nr >= N || nc < 0 || nc >= N || map[nr][nc] == 1 || isVisited[nr][nc]) continue; + if(map[nr][nc] == 0) empty--; + if(empty == 0) { + min = Math.min(min, v.status+1); + return; + } + isVisited[nr][nc] = true; + queue.offer(new Virus(nr, nc, v.status+1)); + } + } + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + virus = new ArrayList(); + empty = 0; + map = new int[N][N]; + int num; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + num = Integer.parseInt(st.nextToken()); + map[i][j] = num; + if(num == 2) { + virus.add(new Virus(i, j, -1)); + }else if(num == 0) empty++; + } + } + + min = Integer.MAX_VALUE; + } +} diff --git "a/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_1749_\354\240\220\354\210\230\353\224\260\353\250\271\352\270\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_1749_\354\240\220\354\210\230\353\224\260\353\250\271\352\270\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" new file mode 100644 index 0000000..2bb10e1 --- /dev/null +++ "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_1749_\354\240\220\354\210\230\353\224\260\353\250\271\352\270\260_\352\263\250\353\223\2344_\355\225\250\354\206\214\354\227\260.java" @@ -0,0 +1,51 @@ +package 기출_문자열; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_1749_점수따먹기_골드4_함소연 { + static int N, M, max = Integer.MIN_VALUE; + static int[][] map; + public static void main(String[] args) throws IOException { + input(); + go(); + System.out.println(max); + } + + private static void go() { + int cnt = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + for (int r = i; r < N; r++) { + for (int c = j; c < M; c++) { + cnt = map[r][c]; + if(j-1 >= 0) cnt -= map[r][j-1]; + if(i-1 >= 0) cnt -= map[i-1][c]; + if(i-1 >=0 && j-1 >=0 ) cnt += map[i-1][j-1]; + max = Math.max(max, cnt); + } + } + } + } + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if(i - 1 >= 0) map[i][j] += map[i-1][j]; + if(j - 1 >= 0) map[i][j] += map[i][j-1]; + if(i - 1 >= 0 && j - 1>= 0) map[i][j] -= map[i-1][j-1]; + } + } + } +} diff --git "a/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_2015_\354\210\230\353\223\244\354\235\230\355\225\2514_\352\263\250\353\223\2344_\355\225\250\354\210\230\354\227\260.java" "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_2015_\354\210\230\353\223\244\354\235\230\355\225\2514_\352\263\250\353\223\2344_\355\225\250\354\210\230\354\227\260.java" new file mode 100644 index 0000000..600d362 --- /dev/null +++ "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_2015_\354\210\230\353\223\244\354\235\230\355\225\2514_\352\263\250\353\223\2344_\355\225\250\354\210\230\354\227\260.java" @@ -0,0 +1,37 @@ +package 기출_문자열; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class Main_백준_2015_수들의합4_골드4_함수연 { + static int N, K; + static long res; + static int[] arr; + static Map map = new HashMap(); + public static void main(String[] args) throws IOException { + input(); + System.out.println(res); + } + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + arr = new int[N+1]; + st = new StringTokenizer(br.readLine(), " "); + + for (int i = 1; i <= N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + arr[i] += arr[i-1]; + if(arr[i] == K) res++; + res += map.getOrDefault(arr[i] - K, (long) 0); + map.put(arr[i], map.getOrDefault(arr[i], (long) 0) + 1); + } + } +} + diff --git "a/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_20437_\353\254\270\354\236\220\354\227\264\352\262\214\354\236\2042_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_268ms.java" "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_20437_\353\254\270\354\236\220\354\227\264\352\262\214\354\236\2042_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_268ms.java" new file mode 100644 index 0000000..1244797 --- /dev/null +++ "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Main_\353\260\261\354\244\200_20437_\353\254\270\354\236\220\354\227\264\352\262\214\354\236\2042_\352\263\250\353\223\2345_\355\225\250\354\206\214\354\227\260_268ms.java" @@ -0,0 +1,76 @@ +package 기출_문자열; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main_백준_20437_문자열게임2_골드5_함소연_268ms { + static StringBuilder sb = new StringBuilder(); + static int T, K, ans1, ans2; + static char[] W; + public static void main(String[] args) throws NumberFormatException, IOException { + input(); + } // end of main + + private static void input() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + T = Integer.parseInt(br.readLine()); + + while(T-- > 0) { + W = br.readLine().toCharArray(); + K = Integer.parseInt(br.readLine()); + if(K == 1) { + sb.append("1 1"+"\n"); + continue; + } + ans1 = 987654321; + ans2 = 0; + go(); + if(ans1 == 987654321 ) + sb.append(-1+"\n"); + else + sb.append(ans1+" "+ans2+"\n"); + } + + System.out.println(sb.toString()); + } // end of input + + private static void go() { + int l, r, cnt; + char start; + int[] ch = new int[26]; + // 최소 K개 이상인 알파벳 찾기 + for (int i = 0; i < W.length; i++) { + ch[W[i] - 'a']++; + } + + // 가장 짧은 문자열, 가장 긴 문자열 찾기 + for (int i = 0; i < 26; i++) { + if(ch[i] >= K) { + start = (char)( i + 'a'); // K개 이상인 알파벳 + find(start, ch[i]-1); + } + } + } // end of go + + private static void find(char s, int idx) { + int l, cnt, time, t = 0; + for (int i = 0; i < W.length; i++) { + if(t == idx) return; // 마지막 문자는 뒤를 찾을 수 없으므로 return + if(W[i] == s) { + cnt = 1; l = i; time = 2; + for (int r = l + 1; r < W.length; r++) { + if(W[l] == W[r]) { + cnt++; + if(cnt == K) { + ans1 = Math.min(ans1, time); + ans2 = Math.max(ans2, time); + break; + } + } + time++; + } + } + } + } +} // end of class diff --git "a/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Solution_Programmers_\354\275\224\353\224\251\355\205\214\354\212\244\355\212\270\352\263\265\353\266\200.java" "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Solution_Programmers_\354\275\224\353\224\251\355\205\214\354\212\244\355\212\270\352\263\265\353\266\200.java" new file mode 100644 index 0000000..403d2bd --- /dev/null +++ "b/\352\270\260\354\266\234_\353\254\270\354\236\220\354\227\264/Solution_Programmers_\354\275\224\353\224\251\355\205\214\354\212\244\355\212\270\352\263\265\353\266\200.java" @@ -0,0 +1,67 @@ +package 기출_문자열; + +import java.util.Arrays; + +public class Solution_Programmers_코딩테스트공부 { + public static void main(String[] args) { + int alp = 10; + int cop = 0; + int[][] problems = {{10,15,2,1,2},{20,20,3,3,4}}; + + //2 +// int alp = 0; +// int cop = 0; +// int[][] problems = {{0,0,2,1,2},{4,5,3,1,2},{4,11,4,0,2},{10,4,0,4,2}}; + + System.out.println(solution(alp, cop, problems)); + } + + public static int solution(int alp, int cop, int[][] problems) { + int A = 0; int C = 0; + int answer = 0; + for (int[] p : problems) { + A = Math.max(A, p[0]); + C = Math.max(C, p[1]); + } + if(alp >= A) alp = A; + if(cop >= C) cop = C; + + int[][] dp = new int[A+2][C+2]; + + for (int i = alp; i <= A; i++) { + for (int j = cop; j <= C; j++) { + dp[i][j] = Integer.MAX_VALUE; + } + } + + dp[alp][cop] = 0; + for (int i = alp; i <= A; i++) { + for (int j = cop; j <= C; j++) { + + } + } +// while(true) { +// if(i == problems.length) break; +// if(alp >= problems[i][0] && cop >= problems[i][1]) { +// alp += problems[i][2]; +// cop += problems[i][3]; +// answer += 2; +// i++; +// } +// else if (alp < problems[i][0] && cop >= problems[i][1]){ +// answer += problems[i][0] - alp; +// alp = problems[i][0]; +// } else if (alp >= problems[i][0] && cop < problems[i][1]) { +// answer += problems[i][1] - cop; +// cop = problems[i][1]; +// }else { +// int sum = problems[i][0] - alp + problems[i][1] - cop; +// alp = problems[i][0]; +// cop = problems[i][1]; +// answer += sum; +// } +// System.out.println(answer); +// } + return answer; + } +} From 80409fb6a4bfad81972b15aaceda485c70c23d9d Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 25 Apr 2023 20:13:23 +0900 Subject: [PATCH 28/30] =?UTF-8?q?4=EC=9B=94=204=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\231_\352\263\250\353\223\2344_80ms.java" | 72 +++++++++ ...54\241\260_\352\263\250\353\223\2343.java" | 141 ++++++++++++++++++ ...\264_\354\213\244\353\262\2043_196ms.java" | 37 +++++ ...54\226\274_\353\240\210\353\262\2502.java" | 58 +++++++ ...54\207\240_\353\240\210\353\262\2503.java" | 83 +++++++++++ ...54\247\221_\353\240\210\353\262\2503.java" | 81 ++++++++++ 6 files changed, 472 insertions(+) create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_23354_\352\265\260\355\203\210\354\262\264\355\217\254\354\241\260_\352\263\250\353\223\2343.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_2559_\354\210\230\354\227\264_\354\213\244\353\262\2043_196ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274_\353\240\210\353\262\2502.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\216\270\354\247\221_\353\240\210\353\262\2503.java" diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" new file mode 100644 index 0000000..0162abf --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" @@ -0,0 +1,72 @@ +package 코테기출3; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_1565_수학_골드4_80ms { + static int D, M, cnt = 0; + static int[] arrD, arrM; + public static void main(String[] args) throws IOException { + input(); + go(); + } + + private static void go() { + long num1 = arrD[0]; + for (int i = 0; i < arrD.length; i++) { + num1 = lcm(num1, arrD[i]); + } + + long num2 = arrM[0]; + for (int i = 0; i < arrM.length; i++) { + num2 = gcd(num2, arrM[i]); + } + // 약수 구하기 + int i = 0; + for (i = 1; i*i < num2 ; i++) { + if(num2%i == 0) { + if(i%num1 == 0) cnt++; + if((num2 / i) % num1 == 0) cnt++; + } + } + if(i*i == num2 && (i%num1== 0)) cnt++; + System.out.println(cnt); + } + + + + private static long lcm(long a, long b) { + return a * b / gcd(a, b); + } + + private static long gcd(long a, long b) { + long c; + while(b != 0) { + c = a % b; + a = b; + b = c; + } + return a; + } + + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + + D = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine(), " "); + arrD = new int[D]; + for (int i = 0; i < D; i++) { + arrD[i] = Integer.parseInt(st.nextToken()); + } + st = new StringTokenizer(br.readLine(), " "); + arrM = new int[M]; + for (int i = 0; i < M; i++) { + arrM[i] = Integer.parseInt(st.nextToken()); + } + } +} \ No newline at end of file diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_23354_\352\265\260\355\203\210\354\262\264\355\217\254\354\241\260_\352\263\250\353\223\2343.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_23354_\352\265\260\355\203\210\354\262\264\355\217\254\354\241\260_\352\263\250\353\223\2343.java" new file mode 100644 index 0000000..95a5491 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_23354_\352\265\260\355\203\210\354\262\264\355\217\254\354\241\260_\352\263\250\353\223\2343.java" @@ -0,0 +1,141 @@ +package 코테기출3; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class Main_백준_23354_군탈체포조_골드3 { + static class Pos{ + int r, c; + + public Pos(int r, int c) { + this.r = r; + this.c = c; + } + } + static int N, sr, sc, min = Integer.MAX_VALUE, distance, INF=Integer.MAX_VALUE; + static int[][] map; + static int[] numbers; + static boolean[] isSelected; + static boolean[][] isVisited; + static int[] dr = {0,0,-1,1}; + static int[] dc = {1,-1,0,0}; + static int[][] dp; + static List list = new ArrayList<>(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + StringTokenizer st; + map = new int[N][N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if(map[i][j] == -1) { + sr = i; + sc = j; + }else if(map[i][j] == 0) { + list.add(new Pos(i, j)); + } + } + } + if(list.isEmpty()) { + System.out.println(0); + System.exit(0); + } + if(list.size() == 1) { + distance = INF; + isVisited = new boolean[N][N]; + go(sr, sc, list.get(0).r, list.get(0).c, 0); + System.out.println(distance*2); + System.exit(0); + } + dp = new int[list.size()+1][list.size()+1]; + + for (int i = 0; i < list.size()+1; i++) { + for (int j = 0; j < list.size()+1; j++) { + if(i==j) continue; + dp[i][j] = INF; + } + } + + // 조합으로 거리 저장 + numbers = new int[2]; + isSelected = new boolean[list.size()]; + comb(0, 0); + + for (int i = 0; i < list.size(); i++) { + distance = INF; + isVisited = new boolean[N][N]; + go(sr, sc, list.get(i).r, list.get(i).c, 0); + dp[0][i+1] = distance; + dp[i+1][0] = distance; + } + + + numbers = new int[list.size()]; + isSelected = new boolean[list.size()+1]; + perm(0, 0, 0); + System.out.println(min); + } + private static void comb(int idx, int start) { + if(idx == 2) { + for (int i = 0, j = 0; i < list.size(); i++) { + if(isSelected[i]) { + numbers[j++] = i; + } + } + distance = INF; + isVisited = new boolean[N][N]; + go(list.get(numbers[0]).r, list.get(numbers[0]).c, list.get(numbers[1]).r, list.get(numbers[1]).c, 0); + dp[numbers[0]+1][numbers[1]+1] = distance; + dp[numbers[1]+1][numbers[0]+1] = distance; + return; + } + for (int i = start; i < list.size(); i++) { + isSelected[i] = true; + comb(idx+1, i+1); + isSelected[i] = false; + } + } + private static void perm(int idx, int prev, int sum) { + if(idx == list.size()) { + sum += dp[0][numbers[idx-1]]; + min = Math.min(sum, min); + return; + } + + if(sum > min) return; + for (int i = 1; i < list.size()+1; i++) { + if(isSelected[i-1]) continue; + isSelected[i-1] = true; + numbers[idx] = i; + perm(idx+1, numbers[idx], sum+dp[prev][numbers[idx]]); + isSelected[i-1] = false; + } + } + private static void go(int r, int c, int tr, int tc, int sum) { + if(tr == r && tc == c) { + distance = sum; + return; + } + if(sum > distance) { + return; + } + int nr, nc; + for (int i = 0; i < 4; i++) { + nr = r + dr[i]; + nc = c + dc[i]; + if(nr < 0 || nr >= N || nc < 0 || nc >= N || isVisited[nr][nc]) continue; + isVisited[nr][nc] = true; + int num = map[nr][nc]; + if(num == -1) num = 0; + go(nr, nc, tr, tc, sum+num); + isVisited[nr][nc] = false; + } + + } +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_2559_\354\210\230\354\227\264_\354\213\244\353\262\2043_196ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_2559_\354\210\230\354\227\264_\354\213\244\353\262\2043_196ms.java" new file mode 100644 index 0000000..fa4981a --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_2559_\354\210\230\354\227\264_\354\213\244\353\262\2043_196ms.java" @@ -0,0 +1,37 @@ +package 코테기출3; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_백준_2559_수열_실버3_196ms { + static int N, K, num, max = -987654321; + static int[] arr; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + arr = new int[N]; + st = new StringTokenizer(br.readLine(), " "); + arr[0] = Integer.parseInt(st.nextToken()); + for (int i = 1; i < K; i++) { + num = Integer.parseInt(st.nextToken()); + arr[i] = arr[i-1] + num; + } + max = arr[K-1]; + if(K == N) { + System.out.println(max); + }else { + for (int i = K; i < N; i++) { + num = Integer.parseInt(st.nextToken()); + arr[i] += arr[i-1] + num; + if(max < arr[i] - arr[i-K]) { + max = arr[i] - arr[i-K]; + } + } + System.out.println(max); + } + } +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274_\353\240\210\353\262\2502.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274_\353\240\210\353\262\2502.java" new file mode 100644 index 0000000..84006f8 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274_\353\240\210\353\262\2502.java" @@ -0,0 +1,58 @@ +package 코테기출3; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Solution_프로그래머스_메뉴리뉴얼_레벨2 { + static Map map; + static int max = 0; + static List list = new ArrayList<>(); + public static void main(String[] args) { + String[] orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int[] course = {2,3,4}; + solution(orders, course); + } + public static String[] solution(String[] orders, int[] course) { + + for (int i = 0; i < course.length; i++) { + map = new HashMap<>(); + max = 0; + for (int j = 0; j < orders.length; j++) { + char[] ch = orders[j].toCharArray(); + Arrays.sort(ch); + orders[j] = new String(ch); + comb(orders[j], course[i], "", 0, 0); + } + + for (String key : map.keySet()) { + max=Math.max(max, map.get(key)); + } + + + for (String key : map.keySet()) { + if(map.get(key) > 1 && map.get(key) == max) { + list.add(key); + } + } + } + + Collections.sort(list); + String[] answer = list.toArray(new String[list.size()]); + return answer; + } + + private static void comb(String order, int end, String temp, int idx, int start) { + if(idx == end) { + map.put(temp, map.getOrDefault(temp, 0)+1); + return; + } + + for (int i = start; i < order.length(); i++) { + comb(order, end, temp+order.charAt(i), idx+1, i+1); + } + } +} \ No newline at end of file diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" new file mode 100644 index 0000000..2cf1ada --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" @@ -0,0 +1,83 @@ +package 코테기출3; +import java.util.Arrays; + +public class Solution_프로그래머스_자물쇠와열쇠_레벨3 { + public static void main(String[] args) { +// int[][] key = {{0, 0, 0}, {1, 0, 0}, {0, 1, 1}}; +// int[][] lock = {{1, 1, 1}, {1, 1, 0}, {1, 0, 1}}; +// int[][] key = {{0, 0, 0}, {0, 0, 0}, {0, 0, 1}}; +// int[][] lock = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; + int[][] key = {{0, 0}, {0, 0}}; + int[][] lock = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + System.out.println(solution(key, lock)); + } + static int M, N; + public static boolean solution(int[][] key, int[][] lock) { + M = key.length; + N = lock.length; + boolean flag= false; + for (int i = 0; i < lock.length; i++) { + for (int j = 0; j < lock.length; j++) { + if(lock[i][j] != 0) { + flag = true; + break; + } + } + } + if(!flag) return true; + int[][] map = new int[N+M*2-2][N+M*2-2]; + for (int i = 0; i < map.length-M+1; i++) { + for (int j = 0; j < map.length-M+1; j++) { + int[][] temp1 = new int[M][M]; + int[][] temp2 = key; + // 90도 회전 + for (int k = 0; k < 4; k++) { + for (int r = 0; r < M; r++) { + for (int c = 0; c < M; c++) { + temp1[r][c] = temp2[c][M-1-r]; + } + } + map = new int[N+M*2-2][N+M*2-2]; + map = change(map, temp1, i, j); + print(temp1); + print(map); + if(check(map, lock)) + return true; + for (int d = 0; d < M; d++) { + temp2[d] = Arrays.copyOf(temp1[d], M); + } + } + } + } + return false; + } + + private static int[][] change(int[][] map, int[][] temp, int sr, int sc) { + for (int i = sr, r = 0; i < sr+M; i++, r++) { + for (int j = sc, c = 0; j < sc+M; j++, c++) { + map[i][j] = temp[r][c]; + } + } + return map; + } + + private static boolean check(int[][] map, int[][] lock) { + for (int i = N-1, r = 0; r < N; i++, r++) { + for (int j = N-1, c = 0; j < N; j++, c++) { + if(lock[r][c] == 1 && map[i][j] == 1) return false; + if(lock[r][c] == 0 && map[i][j] == 0) return false; + } + } + return true; + } + private static void print(int[][] arr) { + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr.length; j++) { + System.out.print(arr[i][j] + " "); + } + System.out.println(); + } + System.out.println(); + } + +} \ No newline at end of file diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\216\270\354\247\221_\353\240\210\353\262\2503.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\216\270\354\247\221_\353\240\210\353\262\2503.java" new file mode 100644 index 0000000..a6a84ca --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\216\270\354\247\221_\353\240\210\353\262\2503.java" @@ -0,0 +1,81 @@ +package 코테기출3; +import java.util.LinkedList; +import java.util.List; +import java.util.Stack; +import java.util.StringTokenizer; + +public class Solution_프로그래머스_표편집_레벨3 { + public static void main(String[] args) { +// int n = 8; +// int k = 2; +// String[] cmd = {"D 2","C","U 3","C","D 4","C","U 2","Z","Z","U 1","C"}; + int n = 8; + int k = 2; + String[] cmd = {"D 2","C","U 3","C","D 4","C","U 2","Z","Z"}; + System.out.println(solution(n, k, cmd)); + } + + static int cur; + static StringTokenizer st; + static List list = new LinkedList<>(); + static Stack del = new Stack<>(); + static StringBuilder sb; + public static String solution(int n, int k, String[] cmd) { + sb = new StringBuilder(); + for (int i = 0; i < n; i++) { + list.add("O"); + } + cur = k; int num = 0; int temp = 0; int cnt = 0; + for (int i = 0; i < cmd.length; i++) { + st = new StringTokenizer(cmd[i], " "); + switch (st.nextToken()) { + case "U": + num = Integer.parseInt(st.nextToken()); + cnt = 0; + for (int j = cur-1; j >= 0; j--) { + if(list.get(j) == "X") continue; + if(cnt == num) break; + cnt++; + cur = j; + } + break; + case "D": + num = Integer.parseInt(st.nextToken()); + cnt = 0; + for (int j = cur+1; j < n; j++) { + if(list.get(j) == "X") continue; + if(cnt == num) break; + cnt++; + cur = j; + } + break; + case "C": + list.set(cur, "X"); + del.add(cur); + temp = cur; + for (int j = cur+1; j < n; j++) { + if(list.get(j) == "X") continue; + cur = j; + break; + } + if(cur == temp) { + for (int j = temp; j >= 0; j--) { + if(list.get(j) == "X") continue; + cur = j; + break; + } + } + break; + case "Z": + list.set(del.pop(), "O"); + break; + default: + break; + } + } + for (int i = 0; i < n; i++) { + sb.append(list.get(i)); + } + return sb.toString(); + } +} \ No newline at end of file From fc3581acd598b8b5d7c536e2107a271fc1d6c054 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 25 Apr 2023 21:09:01 +0900 Subject: [PATCH 29/30] =?UTF-8?q?4=EC=9B=94=204=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\207\240_\353\240\210\353\262\2503.java" | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" index 2cf1ada..736aac2 100644 --- "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" @@ -15,16 +15,6 @@ public static void main(String[] args) { public static boolean solution(int[][] key, int[][] lock) { M = key.length; N = lock.length; - boolean flag= false; - for (int i = 0; i < lock.length; i++) { - for (int j = 0; j < lock.length; j++) { - if(lock[i][j] != 0) { - flag = true; - break; - } - } - } - if(!flag) return true; int[][] map = new int[N+M*2-2][N+M*2-2]; for (int i = 0; i < map.length-M+1; i++) { for (int j = 0; j < map.length-M+1; j++) { @@ -39,8 +29,6 @@ public static boolean solution(int[][] key, int[][] lock) { } map = new int[N+M*2-2][N+M*2-2]; map = change(map, temp1, i, j); - print(temp1); - print(map); if(check(map, lock)) return true; for (int d = 0; d < M; d++) { @@ -62,22 +50,12 @@ private static int[][] change(int[][] map, int[][] temp, int sr, int sc) { } private static boolean check(int[][] map, int[][] lock) { - for (int i = N-1, r = 0; r < N; i++, r++) { - for (int j = N-1, c = 0; j < N; j++, c++) { + for (int i = M-1, r = 0; i < N+M-1; i++, r++) { + for (int j = M-1, c = 0; j < N+M-1; j++, c++) { if(lock[r][c] == 1 && map[i][j] == 1) return false; if(lock[r][c] == 0 && map[i][j] == 0) return false; } } return true; } - private static void print(int[][] arr) { - for (int i = 0; i < arr.length; i++) { - for (int j = 0; j < arr.length; j++) { - System.out.print(arr[i][j] + " "); - } - System.out.println(); - } - System.out.println(); - } - } \ No newline at end of file From d5fc7b28eddb2f00ef11eaa9b4c00fe5d6f574c1 Mon Sep 17 00:00:00 2001 From: soyeon37 Date: Tue, 9 May 2023 00:39:50 +0900 Subject: [PATCH 30/30] =?UTF-8?q?5=EC=9B=94=202=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\231_\352\263\250\353\223\2344_80ms.java" | 2 +- ...54\207\240_\353\240\210\353\262\2503.java" | 6 +- ...\244_\352\263\250\353\223\2342_180ms.java" | 109 ++++++++++++++++++ ...\353\252\205\353\240\271\354\226\264.java" | 43 +++++++ ...\352\266\201\353\214\200\355\232\214.java" | 69 +++++++++++ ...\354\235\270\355\226\211\354\202\254.java" | 57 +++++++++ ...\354\247\204\355\212\270\353\246\254.java" | 13 +++ 7 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2344/Main_\353\260\261\354\244\200_22255_\355\230\270\354\204\235\354\202\254\354\232\260\353\245\264\354\212\244_\352\263\250\353\223\2342_180ms.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\226\221\352\266\201\353\214\200\355\232\214.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.java" create mode 100644 "\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\230\204\352\260\200\353\212\245\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" index 0162abf..13aa59f 100644 --- "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Main_\353\260\261\354\244\200_1565_\354\210\230\355\225\231_\352\263\250\353\223\2344_80ms.java" @@ -23,7 +23,7 @@ private static void go() { for (int i = 0; i < arrM.length; i++) { num2 = gcd(num2, arrM[i]); } - // 약수 구하기 + // 약수 개수 구하기 int i = 0; for (i = 1; i*i < num2 ; i++) { if(num2%i == 0) { diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" index 736aac2..b72876f 100644 --- "a/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2343/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\236\220\353\254\274\354\207\240\354\231\200\354\227\264\354\207\240_\353\240\210\353\262\2503.java" @@ -7,8 +7,10 @@ public static void main(String[] args) { // int[][] lock = {{1, 1, 1}, {1, 1, 0}, {1, 0, 1}}; // int[][] key = {{0, 0, 0}, {0, 0, 0}, {0, 0, 1}}; // int[][] lock = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; - int[][] key = {{0, 0}, {0, 0}}; - int[][] lock = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + int[][] key = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; + int[][] lock = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; +// int[][] key = {{0, 0}, {0, 0}}; +// int[][] lock = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; System.out.println(solution(key, lock)); } static int M, N; diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2344/Main_\353\260\261\354\244\200_22255_\355\230\270\354\204\235\354\202\254\354\232\260\353\245\264\354\212\244_\352\263\250\353\223\2342_180ms.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Main_\353\260\261\354\244\200_22255_\355\230\270\354\204\235\354\202\254\354\232\260\353\245\264\354\212\244_\352\263\250\353\223\2342_180ms.java" new file mode 100644 index 0000000..bbfb2f9 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Main_\353\260\261\354\244\200_22255_\355\230\270\354\204\235\354\202\254\354\232\260\353\245\264\354\212\244_\352\263\250\353\223\2342_180ms.java" @@ -0,0 +1,109 @@ +package 코테기출4; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + + +public class Main_백준_22255_호석사우르스_골드2_180ms { + static int N, M, sr, sc, er, ec, INF = Integer.MAX_VALUE, res = -1; + static int[][] map; + static int[][][] adj; + static int[] dr = {-1, 1, 0, 0}; + static int[] dc = {0, 0, -1, 1}; + static class Node implements Comparable { + int r, c, index, cost; + public Node(int r, int c, int index, int cost) { + this.r = r; + this.c = c; + this.index = index; + this.cost = cost; + } + @Override + public int compareTo(Node o) { + return this.cost - o.cost; + } + } + public static void main(String[] args) throws IOException { + input(); + go(); + if(res == -1) { + System.out.println(-1); + }else + System.out.println(adj[er][ec][res%3]); + } + private static void go() { + PriorityQueue pq = new PriorityQueue(); + pq.offer(new Node(sr, sc, 1, 0)); + int nr, nc = 0; + while(pq.size() > 0) { + Node n = pq.poll(); + if(n.r == er && n.c == ec) { + res = n.index; + return; + } + if(n.index%3 == 0) { + for (int i = 0; i < 4; i++) { + nr = n.r + dr[i]; + nc = n.c + dc[i]; + if(nr < 0 || nr >= N || nc < 0 || nc >= M || map[nr][nc] == -1) continue; + if(map[nr][nc] + n.cost < adj[nr][nc][(n.index+1)%3]) { + adj[nr][nc][(n.index+1)%3] = map[nr][nc] + n.cost; + pq.offer(new Node(nr, nc, n.index+1, adj[nr][nc][(n.index+1)%3])); + } + } + }else if(n.index%3 == 1) { + for (int i = 0; i < 2; i++) { + nr = n.r + dr[i]; + nc = n.c + dc[i]; + if(nr < 0 || nr >= N || nc < 0 || nc >= M || map[nr][nc] == -1) continue; + if(map[nr][nc] + n.cost < adj[nr][nc][(n.index+1)%3]) { + adj[nr][nc][(n.index+1)%3] = map[nr][nc] + n.cost; + pq.offer(new Node(nr, nc, n.index+1, adj[nr][nc][(n.index+1)%3])); + } + } + }else { + for (int i = 2; i < 4; i++) { + nr = n.r + dr[i]; + nc = n.c + dc[i]; + if(nr < 0 || nr >= N || nc < 0 || nc >= M || map[nr][nc] == -1) continue; + if(map[nr][nc] + n.cost < adj[nr][nc][(n.index+1)%3]) { + adj[nr][nc][(n.index+1)%3] = map[nr][nc] + n.cost; + pq.offer(new Node(nr, nc, n.index+1, adj[nr][nc][(n.index+1)%3])); + } + } + } + } + } + private static void input() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + st = new StringTokenizer(br.readLine(), " "); + sr = Integer.parseInt(st.nextToken())-1; + sc = Integer.parseInt(st.nextToken())-1; + er = Integer.parseInt(st.nextToken())-1; + ec = Integer.parseInt(st.nextToken())-1; + + map = new int[N][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + adj = new int[N][M][3]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + for (int j2 = 0; j2 < 3; j2++) { + adj[i][j][j2] = INF; + } + } + } + adj[sr][sc][1] = 0; + } +} \ No newline at end of file diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.java" new file mode 100644 index 0000000..a105dd9 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.java" @@ -0,0 +1,43 @@ +package 코테기출4; + +public class Solution_프로그래머스_미로탈출명령어 { + public static void main(String[] args) { + System.out.println(solution(3, 4, 2, 3, 3, 1, 5)); + } + static int[][] map; + static String answer = "impossible"; + static boolean flag = false; + static int[] dr = {1, 0, 0, -1}; + static int[] dc = {0, -1, 1, 0}; + static String[] str = {"d","l","r","u"}; + public static String solution(int n, int m, int x, int y, int r, int c, int k) { + char[] ch = new char[k+1]; + map = new int[n][m]; + go(x-1, y-1, r-1, c-1, "", 0, k); + return answer; + } + private static void go(int x, int y, int r, int c, String string, int cnt, int k) { + if(flag) return; + if(cnt == k) { + if(x == r && y == c) { + flag = true; + answer = string; + } + return; + } + int dist = Math.abs(x-r) + Math.abs(y-c); + if(dist > k - cnt) return; + if(k-cnt - dist%2 == 1) { + return; + } + int nr, nc = 0; + for (int i = 0; i < 4; i++) { + nr = x + dr[i]; + nc = y + dc[i]; + if(nr < 0 || nr >= map.length || nc < 0 || nc >= map[0].length) continue; + string += str[i]; + go(nr, nc, r, c, string, cnt+1, k); + string = string.substring(0, string.length()-1); + } + } +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\226\221\352\266\201\353\214\200\355\232\214.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\226\221\352\266\201\353\214\200\355\232\214.java" new file mode 100644 index 0000000..fdce7b3 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\226\221\352\266\201\353\214\200\355\232\214.java" @@ -0,0 +1,69 @@ +package 코테기출4; + +import java.util.Arrays; + +public class Solution_프로그래머스_양궁대회 { + static int[] answer; + static int max = 0; + public static void main(String[] args) { +// int n = 1; +// int[] info = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int n = 9; + int[] info = { 0,0,1,2,0,1,1,1,1,1,1}; +// int n = 3; +// int[] info = {0,0,1,0,0,0,0,0,0,1,0}; +// int n = 10; +// int[] info = {0,0,0,0,0,0,0,0,3,4,3}; +// int n = 5; +// int[] info = { 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; + + System.out.println(Arrays.toString(solution(n, info))); + } + + public static int[] solution(int n, int[] info) { + answer = new int [11]; + int[] ans = new int[11]; + int[] fail = {-1}; + comb(info, ans, n, 0, 0, 0); + if(max == 0) { + return fail; + } + return answer; + } + + private static void comb(int[] info, int[] ans, int N, int idx, int score, int apeach) { + if (idx == 10) { + if(N > 0) { + ans[10] = N; + } + if(max < score - apeach) { + max = score - apeach; + answer = ans.clone(); + } + if(max == score - apeach) { + if(N > 0) { + ans[10] = N; + } + for (int i = 9; i >= 0; i--) { + if(answer[i] == ans[i]) continue; + if(answer[i] < ans[i] ) { + answer = ans.clone(); + } + break; + } + } + ans[10] = 0; + return; + } + + if (N > info[idx]) { // 라이언 승 + ans[idx] = info[idx]+1; + comb(info, ans, N - info[idx]-1, idx + 1, score+(10-idx), apeach); + ans[idx] = 0; + } + if(info[idx] > 0) // 어피치 승 + comb(info, ans, N, idx + 1, score, apeach+(10-idx)); + if(info[idx] == 0)// 무승부 + comb(info, ans, N, idx + 1, score, apeach); + } +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.java" new file mode 100644 index 0000000..980ee14 --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.java" @@ -0,0 +1,57 @@ +package 코테기출4; + +import java.util.Arrays; + +public class Solution_프로그래머스_이모티콘할인행사 { + static float[] discount; + static int[] answer; + public static void main(String[] args) { +// int[][] users = {{40, 10000}, {25, 10000}}; +// int[] emoticons = {7000, 9000}; + int[][] users = {{40, 2900}, {23, 10000}, {11, 5200}, {5, 5900}, {40, 3100}, {27, 9200}, {32, 6900}}; + int[] emoticons = {1300, 1500, 1600, 4900}; + System.out.println(Arrays.toString(solution(users, emoticons))); + } + + public static int[] solution(int[][] users, int[] emoticons) { + answer = new int[2]; + discount = new float[emoticons.length]; + perm(emoticons.length, 0, users, emoticons); + return answer; + } + + private static void perm(int N, int idx, int[][] users, int[] emoticons) { + if(N == idx) { + check(users, emoticons); + return; + } + for (int i = 10; i <= 40; i+=10) { + discount[idx] = i; + perm(N, idx+1, users, emoticons); + } + } + + private static void check(int[][] users, int[] emoticons) { + int plus = 0; float price = 0; + for (int i = 0; i < users.length; i++) { + float sum = 0; + for (int j = 0; j < discount.length; j++) { + if(users[i][0] <= discount[j]) { + sum += (1 - discount[j]/100) * emoticons[j] ; + } + } + if(sum >= users[i][1]) { + plus++; + }else { + price += sum; + } + } + + if(answer[0] < plus) { + answer[0] = plus; + answer[1] = (int) price; + }else if(answer[0] == plus && answer[1] < price) { + answer[1] = (int) price; + } + } +} diff --git "a/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\230\204\352\260\200\353\212\245\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\230\204\352\260\200\353\212\245\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" new file mode 100644 index 0000000..a27137d --- /dev/null +++ "b/\354\275\224\355\205\214\352\270\260\354\266\2344/Solution_\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\355\221\234\355\230\204\352\260\200\353\212\245\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" @@ -0,0 +1,13 @@ +package 코테기출4; + +public class Solution_프로그래머스_표현가능한이진트리 { + public static void main(String[] args) { + + } + + public static int[] solution(long[] numbers) { + int[] answer = {}; + + return answer; + } +}