CF967D Resource Distribution
思路:
在一堆服务器中,资源最少的那一个是“瓶颈”,由此想到贪心思路。
首先对所有服务器按照资源数量c排序,再从头到尾扫描。对每个位置,根据x1和x2计算出两段连续的服务器集合分别分配给A任务和B任务(还需要枚举分配A和B的先后顺序),如果够用,则有解。所有位置都不行,则无解。
实现:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
pii c[];
int n, x1, x2;
vector<int> check(int a, int b)
{
bool flg = false;
int tmp, tmp2, l, l2, i = ;
for ( ; i < n; i++)
{
tmp = c[i].first; l = (a + tmp - ) / tmp;
if (i + l >= n) continue;
tmp2 = c[i + l].first; l2 = (b + tmp2 - ) / tmp2;
if (i + l + l2 > n) continue;
flg = true; break;
}
vector<int> ans;
if (flg) { ans.push_back(i); ans.push_back(l); ans.push_back(l2); }
return ans;
}
void show(vector<int> & v, bool rev)
{
vector<int> v1, v2;
for (int i = v[]; i < v[] + v[]; i++) v1.push_back(c[i].second);
for (int i = v[] + v[]; i < v[] + v[] + v[]; i++) v2.push_back(c[i].second);
cout << "Yes" << endl;
if (rev)
{
cout << v[] << " " << v[] << endl;
for (auto it: v2) cout << it << " ";
cout << endl;
for (auto it: v1) cout << it << " ";
cout << endl;
}
else
{
cout << v[] << " " << v[] << endl;
for (auto it: v1) cout << it << " ";
cout << endl;
for (auto it: v2) cout << it << " ";
cout << endl;
}
}
int main()
{
while (cin >> n >> x1 >> x2)
{
for (int i = ; i < n; i++) { cin >> c[i].first; c[i].second = i + ; }
sort(c, c + n);
vector<int> ans = check(x1, x2);
if (ans.size()) { show(ans, false); continue; }
ans = check(x2, x1);
if (ans.size()) { show(ans, true); continue; }
cout << "No" << endl;
}
return ;
}
CF967D Resource Distribution的更多相关文章
- 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
- P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1
P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1 May ...
- How to Analyze Java Thread Dumps--reference
原文地址:http://architects.dzone.com/articles/how-analyze-java-thread-dumps The Performance Zone is pres ...
- CodeForces round 967 div2 题解(A~E)
本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...
- How to Analyze Java Thread Dumps
When there is an obstacle, or when a Java based Web application is running much slower than expected ...
- PatentTips - Method and system for browsing things of internet of things on ip using web platform
BACKGROUND The following disclosure relates to a method and system for enabling a user to browse phy ...
- Karmada大规模测试报告发布:突破100倍集群规模
摘要:在本文中,我们将介绍用于测试的相关指标,如何进行大规模测试,以及我们如何实现大规模的集群接入. 本文分享自华为云社区<突破100倍集群规模!Karmada大规模测试报告发布>,作者: ...
- 齐夫定律, Zipf's law,Zipfian distribution
齐夫定律(英语:Zipf's law,IPA英语发音:/ˈzɪf/)是由哈佛大学的语言学家乔治·金斯利·齐夫(George Kingsley Zipf)于1949年发表的实验定律. 它可以表述为: 在 ...
- CG&CAD resource
Computational Geometry The Geometry Center (UIUC) Computational Geometry Pages (UIUC) Geometry in Ac ...
随机推荐
- linux下自动创建设备文件节点---class
在驱动模块初始化函数中实现设备节点的自动创建 我们在刚开始写Linux设备驱动程序的时候,很多时候都是利用mknod命令手动创建设备节点,实际上Linux内核为我们提供了一组函数,可以用来在模块加载的 ...
- HDU2594 Simpsons’ Hidden Talents —— KMP next数组
题目链接:https://vjudge.net/problem/HDU-2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Oth ...
- YTU 2425: C语言习题 输出月份
2425: C语言习题 输出月份 时间限制: 1 Sec 内存限制: 128 MB 提交: 476 解决: 287 题目描述 编写一程序,输入月份号,输出该月的英文月名.例如,输入3,则输出Mar ...
- 区间DP 青蛙的烦恼
池塘中有n片荷叶恰好围成了一个凸多边形,有一只小青蛙恰好站在1号荷叶上,小青蛙想通过最短的路程遍历所有的荷叶(经过一个荷叶一次且仅一次),小青蛙可以从一片荷叶上跳到另外任意一片荷叶上. 输入数据(fr ...
- AutoIt脚本在做自动化操作的时候,如何进行错误捕获?
我的自动化脚本在运行的时候,会生成一个界面,点击该页面上的按钮能够进行自动化操作. 经常遇到的一个问题是: 脚本运行一半,GUI程序出现了异常情况,这个时候,再次点击生成的界面上的按钮,不会有任何反应 ...
- MongoDB 用户名密码登录
Mongodb enable authentication MongoDB 默认直接连接,无须身份验证,如果当前机器可以公网访问,且不注意Mongodb 端口(默认 27017)的开放状态,那么Mon ...
- make的link_directories命令不起作用
按照<CMake Practice>中第六章的设置,采用include_directories命令去寻找共享库的路径,src/CMakeLists.txt如下: ADD_EXECUTABL ...
- cocos2d-x 坐标系解惑
1.CCTouch* touch->getLocation() ---- 返回当前触摸点在openGL坐标系中的位置 openGL坐标系,原点在左下角,x向右为正,y向上为正. 2.CCTouc ...
- js、匿名函数、闭包、回调函数
234567891011121314151617181920212223242526272829303132333435 闭包 闭包:闭包是指有权访问另一个函数作用域中的变量的函数 函数嵌套一个函数, ...
- githunb竟然可以识别MQ4
完全是上班时候突发奇想,没想到能识别.只是没有现成的gitignore