CODING SOLUTION HELP
26.8K subscribers
28 photos
1 video
1.95K links
Download Telegram
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
int n;
cin >> n;
vector<int> ids(n), costs(n);

for (int i = 0; i < n; i++) cin >> ids[i];
for (int i = 0; i < n; i++) cin >> costs[i];

int budget;
cin >> budget;

int maxItems = 0, minCost = 0;

for (int i = 0; i < n; i++) {
int itemCost = costs[i];
int quantity = budget / itemCost;

if (quantity > 0) {
int currentItems = 0, currentCost = 0;

for (int j = 0; j < n; j++) {
if (i != j && ids[i] % ids[j] == 0) {
currentItems += quantity;
currentCost += costs[j] * quantity;
}
}

if (currentItems > maxItems || (currentItems == maxItems && currentCost > minCost)) {
maxItems = currentItems;
minCost = currentCost;
}
}
}

cout << maxItems << " " << minCost << endl;

return 0;
}


C++
Buzz Day Sale - Codevita
Telegram
pair<double, double> r(double px, double py, double x1, double y1, double x2, double y2) {
double a = y2 - y1;
double b = x1 - x2;
double c = x2 * y1 - x1 * y2;
double d = (a * px + b * py + c) / sqrt(a * a + b * b);
double nx = px - 2 * d * (a / sqrt(a * a + b * b));
double ny = py - 2 * d * (b / sqrt(a * a + b * b));
return {nx, ny};
}

int main() {
double ar;
cin >> ar;

double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;

double s = sqrt(ar);
vector<pair<double, double>> cr = {
{0, 0},
{0, s},
{s, s},
{s, 0},
};

set<pair<double, double>> pts(cr.begin(), cr.end());

for (const auto& c : cr) {
auto [rx, ry] = r(c.first, c.second, x1, y1, x2, y2);
pts.insert({rx, ry});
}

for (const auto& p : pts) {
cout << fixed << setprecision(2) << p.first << " " << p.second << endl;
}

return 0;
}

C++
Folded area - Codevita
Telegram
struct P {
    double a, b;
    P(double a = 0, double b = 0) : a(a), b(b) {}
};

P r(const P &p, double t) {
    return P(p.a * cos(t) - p.b * sin(t),
             p.a * sin(t) + p.b * cos(t));
}

pair<double, double> g(const vector<P> &q, double t) {
    double x1 = 1e9, x2 = -1e9, y1 = 1e9, y2 = -1e9;
    for (const auto &p : q) {
        P s = r(p, t);
        x1 = min(x1, s.a);
        x2 = max(x2, s.a);
        y1 = min(y1, s.b);
        y2 = max(y2, s.b);
    }
    return {x2 - x1, y2 - y1};
}

int main() {
    int n;
    cin >> n;
    vector<P> q(n);

    for (int i = 0; i < n; ++i) {
        cin >> q[i].a >> q[i].b;
    }

    double m = 1e9, w = 0, h = 0;

    for (int i = 0; i < 360; ++i) {
        double t = i * M_PI / 180.0;
        auto [cw, ch] = g(q, t);
        double a = cw * ch;
        if (a < m) {
            m = a;
            w = cw;
            h = ch;
        }
    }

    if (w > h) {
        swap(w, h);
    }

    cout << fixed << setprecision(0) << round(w) << " "
         << fixed << setprecision(0) << round(h);

    return 0;
}


C++
Folder Area - Codevita
Telegram -
struct P {
    double a, b;
    P(double a = 0, double b = 0) : a(a), b(b) {}
};

P r(const P &p, double t) {
    return P(p.a * cos(t) - p.b * sin(t),
             p.a * sin(t) + p.b * cos(t));
}

pair<double, double> g(const vector<P> &q, double t) {
    double x1 = 1e9, x2 = -1e9, y1 = 1e9, y2 = -1e9;
    for (const auto &p : q) {
        P s = r(p, t);
        x1 = min(x1, s.a);
        x2 = max(x2, s.a);
        y1 = min(y1, s.b);
        y2 = max(y2, s.b);
    }
    return {x2 - x1, y2 - y1};
}

int main() {
    int n;
    cin >> n;
    vector<P> q(n);

    for (int i = 0; i < n; ++i) {
        cin >> q[i].a >> q[i].b;
    }

    double m = 1e9, w = 0, h = 0;

    for (int i = 0; i < 360; ++i) {
        double t = i * M_PI / 180.0;
        auto [cw, ch] = g(q, t);
        double a = cw * ch;
        if (a < m) {
            m = a;
            w = cw;
            h = ch;
        }
    }

    if (w > h) {
        swap(w, h);
    }

    cout << fixed << setprecision(0) << round(w) << " "
         << fixed << setprecision(0) << round(h);

    return 0;
}