some programs!!!
This commit is contained in:
1 parent
71f1022dea
commit
ca6daa582c
43 files changed
+1452
-381
No files matched your search
@@ -0,0 +1,48 @@
|
||||
#include <iostream>
|
||||
|
||||
constexpr std::size_t MAX_N = 501;
|
||||
constexpr int INF = 0x3f3f3f3f;
|
||||
|
||||
using ChangedCoins = std::tuple<int, int, int, int>;
|
||||
|
||||
constexpr int calc_coin_amount(const ChangedCoins& coins) {
|
||||
return std::get<0>(coins) + std::get<1>(coins) + std::get<2>(coins) + std::get<3>(coins);
|
||||
}
|
||||
|
||||
ChangedCoins dp[MAX_N];
|
||||
|
||||
|
||||
void init_dp() {
|
||||
for (int i = 1; i < MAX_N; i++) {
|
||||
dp[i] = dp[i - 1], std::get<3>(dp[i])++;
|
||||
if (i - 25 >= 0 && calc_coin_amount(dp[i]) > calc_coin_amount(dp[i - 25])) {
|
||||
dp[i] = dp[i - 25], std::get<0>(dp[i])++;
|
||||
}
|
||||
if (i - 10 >= 0 && calc_coin_amount(dp[i]) > calc_coin_amount(dp[i - 10])) {
|
||||
dp[i] = dp[i - 10], std::get<1>(dp[i])++;
|
||||
}
|
||||
if (i - 5 >= 0 && calc_coin_amount(dp[i]) > calc_coin_amount(dp[i - 5])) {
|
||||
dp[i] = dp[i - 5], std::get<2>(dp[i])++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
init_dp();
|
||||
|
||||
int cents;
|
||||
std::cin >> cents;
|
||||
for (int i = 1; std::cin >> cents; i++) {
|
||||
std::cout
|
||||
<< i << ' '
|
||||
<< std::get<0>(dp[cents]) << " QUARTER(S),"
|
||||
<< std::get<1>(dp[cents]) << " DIME(S),"
|
||||
<< std::get<2>(dp[cents]) << " NICKEL(S),"
|
||||
<< std::get<3>(dp[cents]) << " PENNY(S)" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
using IntWithBase = std::string;
|
||||
|
||||
IntWithBase dec_to_base(int x, unsigned short base) {
|
||||
IntWithBase result;
|
||||
while (x) {
|
||||
result += static_cast<char>(x % base + '0');
|
||||
x /= base;
|
||||
}
|
||||
std::reverse(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int op;
|
||||
std::cin >> op;
|
||||
|
||||
for (int x = 0; ; x++) {
|
||||
IntWithBase x7 = dec_to_base(x, 7), x9 = dec_to_base(x, 9);
|
||||
if (x7.length() != 3 || x9.length() != 3) { continue; }
|
||||
if (x7[0] == x9[2] && x7[1] == x9[1] && x7[2] == x9[0]) {
|
||||
if (op == 1) {
|
||||
std::cout << x << std::endl;
|
||||
} else {
|
||||
std::cout << (op == 2 ? x7 : x9) << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
constexpr int DEFAULT_JUMPS = 60, STOP_PUNISHMENT = 3;
|
||||
|
||||
int get_actual_jumps(std::vector<int> counted_jumps) {
|
||||
counted_jumps.push_back(DEFAULT_JUMPS);
|
||||
for (int i = 0; i < counted_jumps.size(); i++) {
|
||||
if (counted_jumps[i] + 3 * i >= DEFAULT_JUMPS - STOP_PUNISHMENT) {
|
||||
return std::min(counted_jumps[i] + STOP_PUNISHMENT * i, DEFAULT_JUMPS)
|
||||
- STOP_PUNISHMENT * i;
|
||||
}
|
||||
}
|
||||
throw std::logic_error("Wrong algorithm");
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
int n, m;
|
||||
std::cin >> n;
|
||||
for (int _ = 0; _ < n; _++) {
|
||||
std::cin >> m;
|
||||
std::vector<int> counted_jumps(m);
|
||||
for (int i = 0; i < m; i++) {
|
||||
std::cin >> counted_jumps[i];
|
||||
}
|
||||
std::cout << get_actual_jumps(counted_jumps) << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user