U E D R , A S I H C RSS

Star/조현태

Star/조현태

느낀점 및 소감

모처럼 아침에 일찍일어나서.. 아침운동삼아 풀어보려고 했던게 화근..T.T
복잡해 보였던 만큼... 복잡했다~!! 이게뭐닝..
그래서..............
약간 느리다!!
빠르게 할 방법이 전혀 생각 안나는건 아니지만.. 오늘은 바쁜 일이 있어서 ^^ 나가봐야하는 관계로..
나~~~~~~~~~~중에 언젠가 시간나고 할일없으면 속도 개선해서 올리겠다.^^
....... 일이있다는 핑계로 귀차니즘을 무마하는....켁;; (생각하기 귀차너~)
바빠도 음악넣어주는 정도의 센스~!
DeadLink

소스코드

~cpp
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

#define FALSE 0
#define TRUE 1

struct SavePoint{
	int x;
	int y;
	int z;
	SavePoint(int inputX, int inputY, int inputZ)
	{
		x = inputX;
		y = inputY;
		z = inputZ;
	}
	bool operator == (const SavePoint& target) const
	{
		return x == target.x && y == target.y && z == target.z;
	}
	bool operator < (const SavePoint& target) const
	{
		if (x == target.x && y == target.y && z < target.z)
			return true;
		if (x == target.x && y < target.y)
			return true;
		if (x < target.x)
			return true;
		return false;
	}
};

map<SavePoint, int>points;
vector<SavePoint> lines[12];
int bigNumber[12];

vector<SavePoint> calculatePoint[10];

bool isCanPut = FALSE;
int minimumNumber = 0;

int Calculate(int number);

bool IsItCan(int number = 0, int sum = 0)
{
	if (12 == number)
	{
		if (FALSE == isCanPut)
		{
			minimumNumber = sum;
        	isCanPut = TRUE;
		}
		else if (minimumNumber > sum)
			minimumNumber = sum;
		return TRUE;
	}
	if (isCanPut && minimumNumber < sum)
		return FALSE;
	for (register int i = 0; i < (int)calculatePoint[bigNumber[number]].size(); ++i)
	{
		for (register int j = 0; j < (int)lines[number].size(); ++j)
		{
			if (calculatePoint[bigNumber[number]][i] == lines[number][j])
			{
				IsItCan(number + 1, sum);
			}

		}
	}
	for (register int i = 0; i < (int)lines[number].size(); ++i)
	{
		if (bigNumber[number] <= points[lines[number][i]])
		{
			bool isInSame = FALSE;
			for (register int j = 0; j < 10 && FALSE == isInSame; ++j)
			{
				for (register int k = 0; k < (int)calculatePoint[j].size(); ++k)
				{
					if (calculatePoint[j][k] == lines[number][i])
					{
						isInSame = TRUE;
						break;
					}
				}
			}
			if (FALSE == isInSame)
			{
				calculatePoint[bigNumber[number]].push_back(lines[number][i]);
				IsItCan(number + 1, sum + bigNumber[number]);
				calculatePoint[bigNumber[number]].pop_back();
			}
		}
	}
	if (isCanPut)
		return TRUE;
	return FALSE;
}

int GetMinimum()
{
	return minimumNumber;
}

int GetMaximum()
{
	int sum = 0;
	for (map<SavePoint, int>::iterator i = points.begin(); i != points.end(); ++i)
		sum += (*i).second;
	return sum;
}

const int START_POINT_Y[4] = {0, 1, 2, 2};
const int END_POINT_Y[4] = {6, 6, 7, 8};

const int START_POINT_Z[4] = {1, 1, 1, 0};

void GetXYZ(int calculateNumber, int i, int j, int k, int& x, int& y, int& z, int& number)
{
	if (0 == calculateNumber)
	{
		x = i; y = j; z = k;
		number = i - 2;
	}
	else if (1 == calculateNumber)
	{
		x = 7 - k; y = i; z = j;
		number = i + 2;
	}
	else if (2 == calculateNumber)
	{
		x = 7 - j; y = 7 - k; z = i;
		number = i + 6;
	}
}

void ChangeXYZ(int& x, int& y, int& z, int calculateNumber)
{
	if (0 == calculateNumber)
	{
		++z;
	}
	else if (1 == calculateNumber)
	{
		--x;
	}
	else if (2 == calculateNumber)
	{
		--y;
	}
}

void Swap(SavePoint& one, SavePoint& another)
{
	SavePoint temp = one;
	one = another;
	another = temp;
}

void main()
{
	printf("5 7 8 9 6 1 9 0 9 8 4 6 <- 요게 기본. 이대로 처보아요~''/ \n");
	for (register int i = 0; i < 12; ++i)
	{
		cin >> bigNumber[i];
	}

	for (register int i = 2; i < 6; ++i)
	{
		int j = START_POINT_Y[i - 2];
		int k = START_POINT_Z[i - 2];
		int x, y, z, number;
		while (j < END_POINT_Y[i - 2])
		{
			for (register int calculateNumber = 0; calculateNumber < 3; ++calculateNumber)
			{
				GetXYZ(calculateNumber, i, j, k, x, y, z, number);
				if (!(4 > i && j == START_POINT_Y[i - 2]))
				{
					if (points.end() == points.find(SavePoint(x, y, z)))
						points[SavePoint(x, y, z)] = bigNumber[number];
					else if (points[SavePoint(x, y, z)] > bigNumber[number])
						points[SavePoint(x, y, z)] = bigNumber[number];
					lines[number].push_back(SavePoint(x, y, z));
				}
				if (!(4 <= i && j == END_POINT_Y[i - 2] - 1))
				{
					ChangeXYZ(x, y, z, calculateNumber);
					if (points.end() == points.find(SavePoint(x, y, z)))
						points[SavePoint(x, y, z)] = bigNumber[number];
					else if (points[SavePoint(x, y, z)] > bigNumber[number])
						points[SavePoint(x, y, z)] = bigNumber[number];
					lines[number].push_back(SavePoint(x, y, z));
				}
			}
			++j;
			++k;
		}
	}
	for (register int i = 0; i < 10; ++i)
	{
		if (0 == i % 4 || 3 == i % 4)
		{
			Swap(lines[i][0], lines[i][5]);
			Swap(lines[i][1], lines[i][6]);
			Swap(lines[i][2], lines[i][7]);
		}
		else
		{
			Swap(lines[i][0], lines[i][7]);
		}
	}

	if (IsItCan())
		cout << GetMinimum() << " " << GetMaximum() << endl;
	else
		cout << "NO SOLUTION" << endl;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:06
Processing time 0.0356 sec