algorithm the necklace - andstudy/forge GitHub Wiki
-
์ธ์ดํด์ ์ด๋ฃฐ ์ ์๋์ง ์ฌ๋ถ๋ ๊ฐ ์์์ ๊ฐ์์ ํฉ์ด ์ง์์ธ์ง๋ฅผ ์ฑํฌํ๋๊ฑธ๋ก ํจ
-
ํ์ ํฌ์ฑ์ด์ผ... ๋ฒ๋ญ!
public void testTwoCircle() { NacklaceMaker nacklace = new NacklaceMaker(); nacklace.add(1,2); nacklace.add(1,2); nacklace.add(4,5); nacklace.add(4,5); ArrayList<Bead> beads = nacklace.makeNacklace(); assertFalse(nacklace.isCircle()); checkBeads(beads); } public void testLine() { NacklaceMaker nacklace = new NacklaceMaker(); nacklace.add(2,3); nacklace.add(2,3); nacklace.add(3,4); nacklace.add(3,4); nacklace.add(4,5); nacklace.add(4,5); ArrayList<Bead> beads = nacklace.makeNacklace(); assertEquals(6,beads.size()); checkBeads(beads); } -
JAVA
import java.util.ArrayList; public class NacklaceMaker { private ArrayList<Bead> beads; public NacklaceMaker(){ beads = new ArrayList<Bead>(); } public void add(int leftColor, int rightColor) { Bead bead = new Bead(leftColor,rightColor); beads.add(bead); } public boolean isCircle() { int [] colorsCount = new int[51]; for(int i=1;i<colorsCount.length;i++){ colorsCount[0] = 0; } //์์ชฝ์ ์นผ๋ผ์ ํฉ์ ์ ์ฅํ๋ค. for(Bead bead : beads){ colorsCount[bead.getLeftColor()]++; colorsCount[bead.getRightColor()]++; } //๋ชจ๋ ์ฐ๊ฒฐ ๋ ์ ์๋ค๋ฉด ์ ๋ ฅ๋ ์นผ๋ผ์ ํฉ์ ๋ชจ๋ 2๋ก ๋๋ ๋จ์ด์ ธ์ผ ๋๋ค. for(int i=1;i<colorsCount.length;i++){ if((colorsCount[i]%2)!=0){ return false; } } return true; } public ArrayList<Bead> makeNacklace() { ArrayList<Bead> resultList = new ArrayList<Bead>(beads.size()); //๊ฒฐ๊ณผ boolean [] isTraveled = new boolean[beads.size()]; // ์ํ ํ๋์ง ์ฌ๋ถ for(int i=0;i<isTraveled.length;i++){ isTraveled[i] = false; } //์์์ ์ฒซ๋ฒ์งธ์ ์ค๋ฅธ์ชฝ์ Bead curBead = getNextBead(beads.get(0).getLeftColor(), isTraveled); while(curBead != null){ resultList.add(curBead); curBead = getNextBead(curBead.getRightColor(), isTraveled); } return resultList; } private Bead getNextBead(int searchColor,boolean [] isTraveled){ for(int i=0;i<beads.size();i++){ if(!isTraveled[i]){ Bead curBean = beads.get(i); if(curBean.getLeftColor() == searchColor || curBean.getRightColor() == searchColor){ if(curBean.getRightColor() == searchColor ){ //์ค๋ฅธ์ชฝ์ด ๊ฐ์ผ๋ฉด ๋ค์ง๋๋ค curBean.switchColor(); } isTraveled[i] = true; return curBean; } } } return null; } } public class Bead { private int leftColor; private int rightColor; public Bead(int color1, int color2) { this.leftColor = color1; this.rightColor = color2; } public void switchColor(){ int temp = leftColor; leftColor = rightColor; rightColor = temp; } public int getLeftColor() { return leftColor; } public int getRightColor() { return rightColor; } public boolean hasColor(int searchColor) { return false; } public String toString(){ return leftColor + " " + rightColor; } } -
TestCase
import java.util.ArrayList; import junit.framework.TestCase; public class NacklaceTestCase extends TestCase { public void testCheckCircle(){ NacklaceMaker nacklace = new NacklaceMaker(); nacklace.add(1,2); nacklace.add(2,3); assertFalse(nacklace.isCircle()); } public void testCheckCircle2(){ NacklaceMaker nacklace = new NacklaceMaker(); nacklace.add(1,50); nacklace.add(50,1); assertTrue(nacklace.isCircle()); } public void testBeadSwitch(){ Bead bead = new Bead(1,2); bead.switchColor(); assertEquals(bead.getLeftColor(), 2); assertEquals(bead.getRightColor(), 1); } public void testMakeNacklace(){ NacklaceMaker nacklace = new NacklaceMaker(); nacklace.add(2,1); nacklace.add(2,2); nacklace.add(3,4); nacklace.add(3,1); nacklace.add(2,4); ArrayList<Bead> beads = nacklace.makeNacklace(); assertEquals(5,beads.size()); checkBeads(beads); } private void checkBeads(ArrayList<Bead> beads){ int prvColor = beads.get(beads.size()-1).getRightColor(); for(Bead bead : beads){ System.out.println(bead); assertEquals(prvColor, bead.getLeftColor()); prvColor = bead.getRightColor(); } assertEquals(beads.get(0).getLeftColor(),beads.get(beads.size()-1).getRightColor()); } }
- Euler Cycle ์ ์ด์ฉํด์ ๋ฌธ์ ํ์์.
- ํฐ ๋ฌธ์ ์์ด๋ณด์ด๋๋ฐ Wrong Answer ๋์ค๋ ๊ฑฐ ๋ณด๋ฉด, ๋ญ๊ฐ ์์ธ ์ฒ๋ฆฌ๋ฅผ ์ ํด ์ค ๊ฑฐ ๊ฐ๊ธฐ๋... -.-;;;
-
ํฌ์ข ๋ ๋๋ถ์ ๋ฒ๊ทธ ํ๋ ์ฐพ์์ต๋๋ค๋ง ์ฌ์ ํ Wrong Answer ๊ฐ ๋์ค๋๊ตฐ์
-
Programming-Challenges ํํ์ด์ง์ ๋ฌธ์ ์ผ์๋ ์์ต๋๋ค. Overall statistics๋ฅผ ๋ณด๋ฉด 152๋ช ์ด๋ Submit์ ํ๋๋ฐ Best Time์ never solved๊ฐ ์ฐํ์๋๊ฑธ๋ก ๋ด์ ์ค๋ฅ์ผ ๊ฐ๋ฅ์ฑ์ด ์ปค์. UVa์ ์ง์ ์ ์ถํด ๋ด์ผ ํ๋๋ฐ ์ ์ง์ฌ์ดํธ๊ฐ ์ฐ๊ฒฐ์ด ์๋๋ค์;
/* @JUDGE_ID:parkpd 110401 Cpp "test" */ /* @BEGIN_OF_SOURCE_CODE */ #include <iostream> #include <vector> #include <set> #include <deque> #include <list> #include <stack> #include <string> #include <algorithm> #include <map> #include <limits> #include <assert.h> #include <iomanip> #include <math.h> //#define _UNIT_TEST #ifdef _UNIT_TEST #include <Windows.h> #endif using namespace std; // Minimum Spanning Tree -> Prim Algorithm ์ ์๊ฐํ๋ฉฐ ํ์์. namespace ATUtil { bool IsInRange(int value, int from, int to) { return (from <= value) && (value <= to); } int ConvertToIndex(char c) { if ('a' <= c && c <= 'z') { return c - 'a'; } else { return -1; } } char ConvertToChar(int i) { return (char)i + 'a'; } #ifdef _UNIT_TEST class CStopWatch { public: CStopWatch() { m_StartTick = GetTickCount(); // gcc ์์ ์ ๋ ์ ์์ผ๋๊น } ~CStopWatch() { cout << "Time passed : " << GetTickCount() - m_StartTick << " milisec.\n"; } int m_StartTick; }; #endif typedef map<int, int> IntDB; typedef vector<int> Ints; typedef list<int> IntList; }; using namespace ATUtil; #ifdef _UNIT_TEST #include "../UnitTest++/src/UnitTest++.h" #ifdef max #undef max #endif int main() { UnitTest::RunAllTests(); char temp; cin >> temp; return 0; } #endif // code implement namespace ATCode { ////////////////////////////////////////////////////////////////////////// // CVertex typedef list<int> VectexList; class CVertex { public: CVertex(int c) : m_Color(c), m_Checked(false) {} int m_Color; bool m_Checked; VectexList m_Neighbors; }; ////////////////////////////////////////////////////////////////////////// // CGraph class CGraph { public: CVertex* GetOrCreate(int c) { VertexMap::iterator it = m_Graph.find(c); if (it == m_Graph.end()) { CVertex* p = new CVertex(c); m_Graph.insert(make_pair(c, p)); return p; } else { return it->second; } } template<typename InputIterator> void AddEdges(InputIterator from, InputIterator to) { for (InputIterator it = from; it != to; it += 2) { AddEdge(*it, *(it + 1)); } } void AddEdge(int c1, int c2) { CVertex* pV1 = GetOrCreate(c1); CVertex* pV2 = GetOrCreate(c2); pV1->m_Neighbors.push_back(c2); pV2->m_Neighbors.push_back(c1); } int Size() const { return (int)m_Graph.size(); } bool IsEulerCycle() { if (m_Graph.empty()) { return false; } // http://www.aistudy.com/math/koenigsberg_bridge_problem.htm // ๊ทธ๋ํ G ๊ฐ ์ค์ผ๋ฌ ์ฌ์ดํด์ ๊ฐ์ง๋ฉด, G ๋ ์ฐ๊ฒฐ๋์ด ์๊ณ ๊ฐ ์ ์ ์ ์ง์ ์ฐจ์์ด๋ค. // G ๊ฐ ์ฐ๊ฒฐ๋ ๊ทธ๋ํ์ด๊ณ ๋ชจ๋ ์ ์ ์ด ์ง์ ์ฐจ์๋ฅผ ๊ฐ์ง๋ฉด G ๋ ์ค์ผ๋ฌ ์ฌ์ดํด์ ๊ฐ์ง๋ค. // ๋ชจ๋ ์ ์ ์ด ์ง์ ์ฐจ์๋ฅผ ๊ฐ์ง๋์ง๋ฅผ ๊ฒ์ฌ ์ค. for (VertexMap::iterator it = m_Graph.begin(); it != m_Graph.end(); ++it) { CVertex* p = it->second; if (p->m_Neighbors.size() % 2 == 1) { return false; } } // G ๊ฐ ์ฐ๊ฒฐ๋ ๊ทธ๋ํ์ธ์ง๋ ์ด๋ป๊ฒ ์ ์ ์์ง? // ์ ์ฅ ํธ๋ฆฌ๊ฐ ์กด์ฌํ๋ ๊ฒ์ ๋ณด์ด๊ธฐ๋ง ํ๋ฉด ๋๋ค๋๋ฐ? // ๋๋น ์ฐ์ ํธ๋ฆฌ, ๊น์ด ์ฐ์ ํธ๋ฆฌ๋ ์ ์ฅํธ๋ฆฌ๋ค. // BFS ๋ฅผ ์จ ๋ณด์. size_t checkedVertex = 0; deque<int> queue; queue.push_back(m_Graph.begin()->first); while (!queue.empty()) { int nodeIndex = queue.front(); queue.pop_front(); CVertex* p = m_Graph[nodeIndex]; if (p->m_Checked) { continue; } p->m_Checked = true; checkedVertex++; VectexList& neighbors = p->m_Neighbors; for (VectexList::iterator it = neighbors.begin(); it != neighbors.end(); ++it) { CVertex* pNode = m_Graph[*it]; queue.push_back(pNode->m_Color); } } // BFS ๋ก ๊ฐ์ง ๋ชปํ๋ vertex ๊ฐ ์๋ค. ์ฐ๊ฒฐ๋์ง ์์์. if (checkedVertex < m_Graph.size()) { return false; } return true; } void EraseFromList(VectexList& neighbors, int num) { for (VectexList::iterator it = neighbors.begin(); it != neighbors.end(); ++it) { if (*it == num) { neighbors.erase(it); return; // ๋ ์ฐพ์ ํ์๋ ์๊ณ , iterator ๋ ๋ฌดํจํ๋๋ฏ๋ก ๋๊ฐ์ } } } bool FindEulerSubCycle(int node, stack<int>& intStack) { CVertex* pFrom = m_Graph[node]; while (!pFrom->m_Neighbors.empty()) { CVertex* pTo = m_Graph[*(pFrom->m_Neighbors.begin())]; EraseFromList(pTo->m_Neighbors, pFrom->m_Color); EraseFromList(pFrom->m_Neighbors, pTo->m_Color); intStack.push(pTo->m_Color); pFrom = pTo; } return true; } string EulerCycle() { stack<int> stackNum; int startNode = m_Graph.begin()->first; stackNum.push(startNode); while (!stackNum.empty()) { FindEulerSubCycle(startNode, stackNum); while(!stackNum.empty()) { // stack ๋์ด ์๋ node ๋ฅผ ํ๋์ฉ ๊บผ๋ธ๋ค. // isolated ๋ node ๋ผ๋ฉด, path ์ ์ถ๊ฐํ ํ ๋ฒ๋ฆฌ๊ณ , // edge ๊ฐ ๋จ์ ์๋ node ๋ผ๋ฉด stack ์ ๋ ์ฑ๋ก ์ด์ node ๋ก ํ์ฅ์ํจ๋ค. // [SedgeWick Part5] startNode = stackNum.top(); CVertex* pStackedNode = m_Graph[startNode]; if (pStackedNode->m_Neighbors.empty()) { stackNum.pop(); m_Path.push_back(startNode); } else { break; } } } char buf[1000]; string ret; for (size_t i = 0; i < m_Path.size() - 1; ++i) { sprintf(buf, "%d %d\n", m_Path[i], m_Path[i + 1]); ret.append(buf); } //sprintf(buf, "%d %d\n", m_Path[m_Path.size() - 1], m_Path[0]); //ret.append(buf); return ret; } typedef map<int, CVertex*> VertexMap; VertexMap m_Graph; vector<int> m_Path; }; /////////////////////////////////////////////////////////////// // CConsole class CConsole { public: static void ConsoleTest(istream& input, ostream& output); }; void CConsole::ConsoleTest(istream& input, ostream& output) { int testCount = 0; input >> testCount; for (int i = 0; i < testCount; ++i) { if (1 <= i) { output << "\n"; } int num = 0; input >> num; CGraph graph; int n1, n2; for (int j = 0; j < num; ++j) { input >> n1 >> n2; graph.AddEdge(n1, n2); } output << "Case #" << i + 1 << "\n"; if (!graph.IsEulerCycle()) { output << "some beads may be lost\n"; } else { // ํด๋ต์ ์๋ค. Euler Cycle ์ ์ฐพ์. output << graph.EulerCycle(); } } }; } using namespace ATCode; #ifndef _UNIT_TEST int main() { CConsole::ConsoleTest(cin, cout); return 0; } #else // tests struct FixtureBase { FixtureBase() { } CGraph g; stringstream input; stringstream output; }; TEST_FIXTURE(FixtureBase, IsEulerCycle3) { int input[] = {1, 1, 1, 1, 1, 1, 1, 1}; g.AddEdges(&input[0], &input[sizeof(input) / sizeof(int)]); CHECK(g.IsEulerCycle()); } TEST_FIXTURE(FixtureBase, IsEulerCycle2) { int input[] = {1, 2, 2, 2, 2, 3, 3, 1}; g.AddEdges(&input[0], &input[sizeof(input) / sizeof(int)]); CHECK(g.IsEulerCycle()); g.AddEdge(3, 4); CHECK(!g.IsEulerCycle()); } TEST_FIXTURE(FixtureBase, IsEulerCycle1) { int input[] = {2, 3, 2, 3, 3, 4, 3, 4, 4, 5, 4, 5}; g.AddEdges(&input[0], &input[sizeof(input) / sizeof(int)]); CHECK(g.IsEulerCycle()); CHECK_EQUAL("2 3\n3 4\n4 5\n5 4\n4 3\n3 2\n", g.EulerCycle()); } TEST_FIXTURE(FixtureBase, IsEulerCycle) { int input[] = {1, 2, 1, 2, 4, 5, 4, 5}; g.AddEdges(&input[0], &input[sizeof(input) / sizeof(int)]); CHECK(!g.IsEulerCycle()); } TEST_FIXTURE(FixtureBase, EulerCycle) { int input[] = {0, 1, 0, 2, 0, 5, 0, 6, 1, 2, 2, 3, 2, 4, 3, 4, 4, 5, 4, 6}; g.AddEdges(&input[0], &input[sizeof(input) / sizeof(int)]); CHECK(g.IsEulerCycle()); CHECK_EQUAL("0 6\n6 4\n4 3\n3 2\n2 4\n4 5\n5 0\n0 2\n2 1\n1 0\n", g.EulerCycle()); } TEST_FIXTURE(FixtureBase, EulerCycle1) { int input[] = {1, 3, 1, 2, 1, 5, 2, 3, 2, 5, 2, 4, 3, 4, 4, 5, 3, 6, 4, 6, 4, 7, 5, 7, 1 ,4}; g.AddEdges(&input[0], &input[sizeof(input) / sizeof(int)]); CHECK(g.IsEulerCycle()); CHECK_EQUAL("1 4\n4 7\n7 5\n5 4\n4 6\n6 3\n3 4\n4 2\n2 5\n5 1\n1 2\n2 3\n3 1\n", g.EulerCycle()); } TEST_FIXTURE(FixtureBase, ConsoleTest2) { input << "2\n" "5\n" "1 2\n" "2 3\n" "3 4\n" "4 5\n" "5 6\n" "5\n" "2 1\n" "2 2\n" "3 4\n" "3 1\n" "2 4\n"; CConsole::ConsoleTest(input, output); CHECK_EQUAL( "Case #1\n" "some beads may be lost\n" "\n" "Case #2\n" "1 3\n" "3 4\n" "4 2\n" "2 2\n" "2 1\n", output.str()); } #endif /* @END_OF_SOURCE_CODE */
-
- ํ ์์ ๊ตฌ์ฌ ๋๋ฌธ์ ์์ธ๊ฐ ๋ง์์ง๊ณ ์ฝ๋๊ฐ ์ง์ ๋ถํจ
Public Class Bead
Sub New(ByVal color1 As Integer, ByVal color2 As Integer)
_color1 = color1
_color2 = color2
End Sub
Function IsThereColor(ByVal color As Integer) As Boolean
If color = Color1 Or color = Color2 Then
Return True
Else
Return False
End If
End Function
Function IsMonoColor() As Boolean
Return (Color1 = Color2)
End Function
Sub ReverseColor()
Dim temp As Integer = Color1
_color1 = Color2
_color2 = temp
End Sub
Private _color1 As Integer
Private _color2 As Integer
ReadOnly Property Color1() As Integer
Get
Return _color1
End Get
End Property
ReadOnly Property Color2() As Integer
Get
Return _color2
End Get
End Property
End Class
Public Class Necklace
Private _isReparable As Boolean
ReadOnly Property IsReparable() As Boolean
Get
Return _isReparable
End Get
End Property
Function AreCountOfColorEven(ByVal beads As List(Of Bead)) As Boolean
Dim colorCount(50) As Integer
For color As Integer = 1 To 50
For Each aBead As Bead In beads
If aBead.Color1 = color Then colorCount(color) += 1
If aBead.Color2 = color Then colorCount(color) += 1
Next
Next
For i As Integer = 1 To 50
If colorCount(i) Mod 2 <> 0 Then Return False
Next
Return True
End Function
Private _repaired As List(Of Bead) = New List(Of Bead)
Function GetRepaired() As List(Of Bead)
Return _repaired
End Function
Sub TryRepair(ByVal beadList As List(Of Bead))
_repaired.Clear()
If Not AreCountOfColorEven(beadList) Then
_isReparable = False
Return
End If
Dim beads As List(Of Bead) = GetCopied(beadList)
Dim monos As List(Of Bead) = GetAndRemoveMono(beads)
Dim areAllMono As Boolean = (monos.Count = beadList.Count)
If areAllMono Then
_isReparable = True
_repaired.InsertRange(0, monos)
Return
End If
Dim startColor As Integer = beads(0).Color1
Dim color As Integer = startColor
While beads.Count > 0
Dim aBead As Bead = GetMatched(color, beads)
If aBead.Color2 = color Then aBead.ReverseColor()
_repaired.Add(aBead)
beads.Remove(aBead)
color = aBead.Color2
If color = startColor Then Exit While
End While
For Each mono As Bead In monos
Dim i As Integer = 0
While True
If i >= _repaired.Count Then Exit While
If _repaired(i).Color2 = mono.Color1 And Not _repaired(i).IsMonoColor() Then
_repaired.Insert(i + 1, mono)
i += 1
End If
i += 1
End While
Next
_isReparable = True
If _repaired.Count <> beadList.Count Then _isReparable = False
If _repaired(0).Color1 <> _repaired(_repaired.Count - 1).Color2 Then _isReparable = False
For i As Integer = 0 To _repaired.Count - 2
If _repaired(i).Color2 <> _repaired(i + 1).Color1 Then _isReparable = False
Next
End Sub
Function GetAndRemoveMono(ByVal beads As List(Of Bead)) As List(Of Bead)
Dim monos As List(Of Bead) = New List(Of Bead)
Dim i As Integer = 0
While True
If i >= beads.Count Then Exit While
If beads(i).IsMonoColor() Then
monos.Add(beads(i))
beads.RemoveAt(i)
Else
i += 1
End If
End While
Return monos
End Function
Shared Function GetCopied(ByVal beadList As List(Of Bead)) As List(Of Bead)
Dim beadArray(beadList.Count - 1) As Bead
beadList.CopyTo(beadArray)
Return New List(Of Bead)(beadArray)
End Function
Function GetMatched(ByVal color As Integer, ByVal beads As List(Of Bead)) As Bead
For Each aBead As Bead In beads
If aBead.IsThereColor(color) Then Return aBead
Next
Return Nothing
End Function
End Class
<TestClass()> _
Public Class NecklaceTest
<TestMethod()> _
Public Sub AreCountOfColorEvenTest()
Dim beads As List(Of Bead) = New List(Of Bead)
beads.Add(New Bead(1, 2))
beads.Add(New Bead(2, 2))
beads.Add(New Bead(2, 3))
beads.Add(New Bead(3, 1))
Dim aNecklace As Necklace = New Necklace
Assert.IsTrue(aNecklace.AreCountOfColorEven(beads))
beads.Add(New Bead(3, 4))
Assert.IsFalse(aNecklace.AreCountOfColorEven(beads))
End Sub
<TestMethod()> _
Public Sub GetCopiedTest()
Dim beads As List(Of Bead) = New List(Of Bead)
beads.Add(New Bead(1, 2))
beads.Add(New Bead(2, 3))
Dim copied As List(Of Bead) = Necklace.GetCopied(beads)
Assert.AreEqual(beads.Count, copied.Count)
Assert.AreEqual(beads(0).Color1, copied(0).Color1)
Assert.AreEqual(beads(1).Color1, copied(1).Color1)
End Sub
<TestMethod()> _
Public Sub GetAndRemoveMonoTest()
Dim beads As List(Of Bead) = New List(Of Bead)
beads.Add(New Bead(1, 2))
beads.Add(New Bead(2, 2))
beads.Add(New Bead(2, 2))
Dim aNecklace As Necklace = New Necklace
Dim monos As List(Of Bead) = aNecklace.GetAndRemoveMono(beads)
Assert.AreEqual(2, monos.Count)
End Sub
<TestMethod()> _
Public Sub GetRepairedTest()
Dim beads As List(Of Bead) = New List(Of Bead)
beads.Add(New Bead(2, 1))
beads.Add(New Bead(2, 2))
beads.Add(New Bead(2, 2))
beads.Add(New Bead(3, 4))
beads.Add(New Bead(3, 1))
beads.Add(New Bead(2, 4))
beads.Add(New Bead(3, 3))
Dim aNecklace As Necklace = New Necklace
aNecklace.TryRepair(beads)
Dim repaired As List(Of Bead) = aNecklace.GetRepaired()
Assert.IsTrue(aNecklace.IsReparable)
Assert.AreEqual(beads.Count, repaired.Count)
Assert.AreEqual(repaired(0).Color1, repaired(repaired.Count - 1).Color2)
For i As Integer = 1 To repaired.Count - 1
Assert.AreEqual(repaired(i - 1).Color2, repaired(i).Color1)
Next
End Sub
<TestMethod()> _
Public Sub GetRepairedTestTwoCircle()
Dim beads As List(Of Bead) = New List(Of Bead)
beads.Add(New Bead(2, 1))
beads.Add(New Bead(1, 2))
beads.Add(New Bead(5, 6))
beads.Add(New Bead(5, 6))
Dim aNecklace As Necklace = New Necklace
aNecklace.TryRepair(beads)
Assert.IsFalse(aNecklace.IsReparable)
End Sub
<TestMethod()> _
Public Sub GetRepairedTestAllMono()
Dim beads As List(Of Bead) = New List(Of Bead)
beads.Add(New Bead(1, 1))
beads.Add(New Bead(1, 1))
beads.Add(New Bead(1, 1))
beads.Add(New Bead(1, 1))
Dim aNecklace As Necklace = New Necklace
aNecklace.TryRepair(beads)
Assert.IsTrue(aNecklace.IsReparable)
End Sub
End Class
- ์ธ์ ํ ๊ตฌ์ฌ๊ณผ ๊ฐ์ ๋ฐ์ชฝ ์๊น์ ๊ฐ๋ ๋ชฉ๊ฑธ์ด๋ฅผ ๋ง๋๋ ๋ฌธ์ !
- ๋ฌดํ BFS ์๋
- ์ญ์ ์์๋๋ก Time Limit..
- Solved ๋ฐ๊ณ ์ถ์ด์~~!