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 ...
随机推荐
- POJ2243 Knight Moves —— A*算法
题目链接:http://poj.org/problem?id=2243 Knight Moves Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- MYSQL初级学习笔记二:数据表相关操作及MySQL存储引擎!(视频序号:初级_5,7-22|6)
知识点三:数据表相关操作(5,7-22) --------------------------------整型--------------------------------- --测试整型 CREA ...
- html5--6-7 CSS选择器4
html5--6-7 CSS选择器4 实例 学习要点 掌握常用的CSS选择器 了解不太常用的CSS选择器 什么是选择器 当我们定义一条样式时候,这条样式会作用于网页当中的某些元素,所谓选择器就是样式作 ...
- Android自动化测试环境搭建
Android自动化环境的搭建主要包括: 1. java jdk和jre的安装和环境的配置 2. appium服务器的安装和配置 3. eclipse开发工具,这里不必要用Android Studio ...
- 我自己常用的Watir自动化测试结果报表
特别声明:该报表框架不是我搭建的.
- 用js实现的一个可拖动标签的例子
先贴代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- Bootstrap-CSS:按钮
ylbtech-Bootstrap-CSS:按钮 1.返回顶部 1. Bootstrap 按钮 本章将通过实例讲解如何使用 Bootstrap 按钮.任何带有 class .btn 的元素都会继承圆角 ...
- bzoj2839
容斥原理+组合数学 看见这种恰有k个的题一般都是容斥原理,因为恰有的限制比较强,一般需要复杂度较高的方法枚举,而容斥就是转化为至少有k个,然后通过容斥原理解决 我们先选出k个元素作为交集,有C(n,k ...
- 关于Android ListView组件中android:drawSelectorOnTop含义(转载)
转自:http://yangguangfu.iteye.com/blog/902559 When set to true, the selector will be drawn over the se ...
- dd 使用记录
使用dd的工具 1)测试写速度 2)测试读速度 3)测试读写速度 dd说明: if是输入文本,of是输出文本,bs是块大小,count是你指定读写块的数量 /dev/zero是从内存里面读取,不会产生 ...