srm 535
来源:互联网 发布:阳江市网络问政平台 编辑:程序博客网 时间:2024/06/05 09:16
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 secondtypedef 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 secondtypedef 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; }};
0 0
- srm 535
- srm
- srm 535 div2 250&500
- topcode srm SRM 557
- SRM 443
- SRM 442
- SRM 439
- SRM 438
- SRM 444
- SRM 434
- SRM 445
- SRM 426
- SRM 456
- SRM 467
- SRM 466
- SRM 465
- SRM 466
- SRM 469
- vs2008转到2013后,在对话框中添加控件程序直接退出
- 职业选择--再温《HP大中华区总裁孙振耀退休感言》(终)
- MFC 多媒体计时器函数timeSetEvent的使用方法
- 如何分析GRE句子填空结构?
- JAVA集群分布式和网络设计的浅析(转载!)
- srm 535
- NFV是下一代MBB网络演进的关键技术
- android 实践基础 AndroidUI性能优化-2015/06/11
- MessageBox、::MessageBox 、AfxMessageBox三者的区别
- com.mongodb.MongoException$CursorNotFound: cursor not found on server异常处理
- HTML5新特性展示利用history.replaceState()修改历史记录
- 黑马程序员——基础篇——接口和多态
- 唯购:开通微信商城,费用全免!
- swift学习记录02-控制语句:分支、循环、跳转