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 ...
随机推荐
- @SpringBootApplication 注解
@SpringBootApplication 启动类注解(一般在root下):该注解被@Configuration.@EnableAutoConfiguration.@ComponentScan 这三 ...
- 基于Delphi7 WebService 在Apache发布及Apache使用说明
基于Delphi7 WebService 在Apache 发布及Apache 使用说明 qq:394251165 前段时间,需要将基于Delphi7 WebService 发布在Apache, 很是苦 ...
- 51Nod 1282 时钟 —— 最小表示法 + 字符串哈希
题目链接:https://vjudge.net/problem/51Nod-1282 1282 时钟 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难 ...
- dedecms获取顶级栏目名称、二级栏目名称实现方法
织梦DEDECMS文章.栏目页获取当前页面顶级栏目名称的方法 在用织梦做一些项目时,时常会碰到需要在当前页面调用顶级栏目名称的时候,织梦默认{dede:field name='typename' /} ...
- 重入锁ReentrantLock用法以及如何实现重进入
在java多线程中,可以使用synchronized实现线程之间的同步互斥,但在jdk1.5中增加了ReentrantLock类也能达到同样的效果,而且在使用上更加灵活,扩展功能上更加强大. 创建My ...
- html5--6-63 布局
html5--6-63 布局 实例 学习要点 掌握传统布局与CSS3新增布局方式的实现和应用 掌握CSS3新增属性box-sizing 了解CSS3新增的多列布局 常用布局方式 固定布局与流体布局的优 ...
- myeclipse8.6注册码
loveyLR8ZC-855550-69545856608357821
- python中PIL.Image和OpenCV图像格式相互转换
PIL.Image转换成OpenCV格式: import cv2 from PIL import Image import numpy image = Image.open("plane.j ...
- 关于将word转化为pdf 文件调用jacob 包
用jacob. 先到官方网站上去下载:http://sourceforge.net/project/showfiles.php?group_id=109543&package_id=11836 ...
- 【ZJOI 2002】 昂贵的聘礼
[题目链接] 点击打开链接 [算法] 最短路,注意不能用dijkstra,要用SPFA [代码] #include <algorithm> #include <bitset> ...