#include <iostream>
#include <ctime>
using namespace std;
int main()
{
clock_t start = clock();
int total = 0;
for (unsigned int i = 0; i <= 200; i++)
for (unsigned int j = 0; i + j * 2 <= 200; j++)
for (unsigned int k = 0; i + j * 2 + k * 5 <= 200; k++)
for (unsigned int l = 0; i + j * 2 + k * 5 + l * 10 <= 200; l++)
for (unsigned int m = 0; i + j * 2 + k * 5 + l * 10 + m * 20 <= 200; m++)
for (unsigned int n = 0; i + j * 2 + k * 5 + l * 10 + m * 20 + n * 50 <= 200; n++)
for (unsigned int o = 0; i + j * 2 + k * 5 + l * 10 + m * 20 + n * 50 + o * 100 <= 200; o++)
for (unsigned int p = 0; i + j * 2 + k * 5 + l * 10 + m * 20 + n * 50 + o * 100 + p * 200 <= 200; p++)
if (i * 1 + j * 2 + k * 5 + l * 10 + m * 20 + n * 50 + o * 100 + p * 200 == 200)
total++;
cout << total << endl
<< "Process took " << (static_cast<double> (clock()) - start) / CLOCKS_PER_SEC << " seconds." << endl;
system ("pause");
return 0;
}
Sunday, November 16, 2008
Problem #31
Heres my code at solving this problem...I also added a timer into the code to calculate how quickly it solves the problems, it solved this one in 0.078 seconds.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment