Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Aug 2, 2019
1 parent cb6d6a0 commit 4c5d905
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 1 deletion.
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "NEW_maximumSum_UVA108"; //*
const string CPPfile = "makingChange_UVA166"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
72 changes: 72 additions & 0 deletions myCpps/makingChange_UVA166.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("makingChange_UVA166.in");
ofstream fout("makingChange_UVA166.out");

const int inf = INT_MAX / 2, N = 1000, ctc = 6;

int main()
{
vector<int> coins = {inf, 5, 10, 20, 50, 100, 200};
vector<vector<int>> dp_infc(ctc + 1, vector<int>(N + 1, inf)); dp_infc[0][0] = 0;
for (int i = 1; i <= ctc; ++i)
{
for (int j = N; j >= 0; --j)
{
for (int c = 0; coins[i] * c <= j; ++c)
{
dp_infc[i][j] = min(dp_infc[i - 1][j], dp_infc[i - 1][j - coins[i] * c] + c);
}
}
}

while (true)
{
vector<int> cc(ctc + 1, inf);
for (int i = 1; i <= ctc; ++i)
{
fin >> cc[i];
}

bool canBreak = true;
for (int i = 1; i <= ctc; ++i)
{
if (cc[i] > 0)
{
canBreak = false;
break;
}
}
if (canBreak == true) break;

double pay_d; fin >> pay_d;
int pay = (int)(pay_d * 100.0 + 0.5);

vector<vector<int>> dp(ctc + 1, vector<int>(N + 1, inf)); dp[0][0] = 0;
for (int i = 1; i <= ctc; ++i)
{
for (int j = N; j >= 0; --j)
{
for (int c = 0; coins[i] * c <= j && c <= cc[i]; ++c)
{
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - coins[i] * c] + c);
}
}
}

int ans = inf;
for (int p = pay; p <= N; ++p)
{
if (ans > dp[ctc][p] + dp_infc[ctc][p - pay])
{
ans = dp[ctc][p] + dp_infc[ctc][p - pay];
}
}

fout << setw(3) << ans << '\n';
}

return 0;
}
30 changes: 30 additions & 0 deletions myCpps/makingChange_UVA166.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
0 0 0 0 0 3 5.00
0 0 0 1 1 2 4.05
0 1 0 0 0 1 1.65
100 0 1 0 0 1 1.35
0 0 0 0 0 1 1.15
0 0 0 0 0 1 0.35
0 1 1 3 1 0 1.35
100 1 1 2 0 0 1.50
1 1 1 3 2 0 1.35
1 1 1 3 1 0 1.35
0 1 1 3 1 1 1.35
5 1 1 4 1 0 2.15
1 1 7 3 1 30 4.35
0 0 0 1 1 0 0.05
0 0 0 0 0 1 0.05
0 0 0 1 0 1 0.05
0 1 0 0 1 0 0.05
0 0 0 0 0 1 0.15
0 0 0 0 0 1 1.15
0 0 0 0 1 1 2.15
0 0 0 0 0 2 3.15
0 0 0 0 0 1 0.95
0 0 0 0 0 1 1.95
0 0 1 3 1 0 0.15
0 1 0 3 1 0 0.35
99 0 0 0 0 1 5.00
99 0 0 0 0 0 4.95
99 1 0 0 1 0 4.95
9 1 1 2 1 2 4.95
0 0 0 0 0 0
29 changes: 29 additions & 0 deletions myCpps/makingChange_UVA166.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
4
6
4
4
5
5
4
8
4
4
4
5
5
4
6
4
2
6
5
6
6
3
2
2
3
61
99
79
4
74 changes: 74 additions & 0 deletions myCpps/makingChange_UVA166OJ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <bits/stdc++.h>

using namespace std;


const int inf = INT_MAX / 2, N = 1000, ctc = 6;

int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
vector<int> coins = {inf, 5, 10, 20, 50, 100, 200};
vector<vector<int>> dp_infc(ctc + 1, vector<int>(N + 1, inf)); dp_infc[0][0] = 0;
for (int i = 1; i <= ctc; ++i)
{
for (int j = N; j >= 0; --j)
{
for (int c = 0; coins[i] * c <= j; ++c)
{
dp_infc[i][j] = min(dp_infc[i - 1][j], dp_infc[i - 1][j - coins[i] * c] + c);
}
}
}

while (true)
{
vector<int> cc(ctc + 1, inf);
for (int i = 1; i <= ctc; ++i)
{
cin >> cc[i];
}

bool canBreak = true;
for (int i = 1; i <= ctc; ++i)
{
if (cc[i] > 0)
{
canBreak = false;
break;
}
}
if (canBreak == true) break;

double pay_d; cin >> pay_d;
int pay = (int)(pay_d * 100.0 + 0.5);

vector<vector<int>> dp(ctc + 1, vector<int>(N + 1, inf)); dp[0][0] = 0;
for (int i = 1; i <= ctc; ++i)
{
for (int j = N; j >= 0; --j)
{
for (int c = 0; coins[i] * c <= j && c <= cc[i]; ++c)
{
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - coins[i] * c] + c);
}
}
}

int ans = inf;
for (int p = pay; p <= N; ++p)
{
if (ans > dp[ctc][p] + dp_infc[ctc][p - pay])
{
ans = dp[ctc][p] + dp_infc[ctc][p - pay];
}
}

cout << setw(3) << ans << '\n';
}

cout.flush();
return 0;
}

0 comments on commit 4c5d905

Please sign in to comment.