U E D R , A S I H C RSS

Marbles/신재동

Marbles/신재동

~cpp 
#include <iostream>
using namespace std;

const int MAX_NUMBER = 1000;

unsigned int testCase = 0;

unsigned int marbles[MAX_NUMBER] = {0,};

unsigned int c1[MAX_NUMBER] = {0,};
unsigned int n1[MAX_NUMBER] = {0,};

unsigned int c2[MAX_NUMBER] = {0,};
unsigned int n2[MAX_NUMBER] = {0,};

unsigned int m1[MAX_NUMBER] = {MAX_NUMBER,};
unsigned int m2[MAX_NUMBER] = {MAX_NUMBER,};

void input();
void process();
void output();

int main()
{	
	input();
	process();
	output();

	return 0;
}

void input()
{
	while(true)
	{
		cin >> marbles[testCase];
		
		if(marbles[testCase] == 0)
			break;

		cin >> c1[testCase] >> n1[testCase];
		cin >> c2[testCase] >> n2[testCase];

		testCase++;
	}
}

void process()
{
	for(int i = 0; i < testCase; i++)
	{
		int maxX = marbles[i] / n1[i];
		int maxY = marbles[i] / n2[i];

		int cost;

		for(int x = 0; x < maxX; x++)
		{
			for(int y = 0; y < maxY; y++)
			{
				cost = c1[i] * x + c2[i] * y;

				if(marbles[i] == n1[i] * x + n2[i] * y)
				{
					if(cost < c1[i] * m1[i] + c2[i] * m2[i])
					{
						m1[i] = x;
						m2[i] = y;
					}
				}
			}
		}
	}
}

void output()
{
	for(unsigned int i = 0; i < testCase; i++)
	{
		if(m1[i] != 0 && m2[i] != 0)
			cout << m1[i] << " " << m2[i] << endl;
		else
			cout << "failed" << endl;
	}
}
---
문제를 푸는 속도에 초점을 두어서 지저분하고 냄새 많이 남. --재동

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:45
Processing time 0.0169 sec