srm 535

250



Description

給a,b的gcd爲G,lcm爲L,求min(a+b)

Solution

水題,把a,b都先除以G,然後枚舉即可

Code

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
class FoxAndGCDLCM {
    public:
        long long get(long long G, long long L) {
            if (L % G != 0) return -1;
            LL t = L / G;
            LL ans = 1000000000000000ll;
            for (LL i = 1; i * i <= t; ++i) {
                if (t % i == 0 && __gcd(i, t / i) == 1) ans = min(ans, G * (t / i + i));
            }
            return ans;
        }
};

500



Description:

給n個人,給定每個人一小時能做多少工作a[i] ,以及每單位工作需要支付他p[i] 元,所有人工作時間相同,每秒需支付額外的1元。問選出K個人完成任務花費最小代價多少。

Solution

不妨考慮使得單位工作代價最小,和所求是等價的。顯然可以二分答案。
易知mid×(a[x]+a[y]+....+a[z])(a[x]p[x]+a[y]p[y]+...+a[z]p[z])+3600K 時,答案可以更小。最後答案乘totwork即可

Code:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
double w[N];
class FoxAndBusiness {
    public:
        double minimumCost(int K, int totalWork, vector <int> a, vector <int> p) {
            int n = a.size();
            double l = 0, r = 1e18, mid;
            for (int i = 1; i <= 500; ++i) {
                mid = (l + r) * 0.5;
                for (int j = 0; j < n; ++j)
                    w[j] = mid * a[j] - (double)a[j] * p[j];
                sort(&w[0], &w[n]);
                reverse(&w[0], &w[n]);
                double t = 0;
                for (int j = 0; j < K; ++j) t += w[j];
                if (t >= 3600.0 * K)    r = mid;
                else l = mid;
            }
            return mid * totalWork;
        }
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章