CF967D Resource Distribution
2024-09-06 15:55:33
思路:
在一堆服务器中,资源最少的那一个是“瓶颈”,由此想到贪心思路。
首先对所有服务器按照资源数量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 ;
}
最新文章
- 获取 windows 商店内的 aapx 安装包 并 安装(旁加载)
- [原创]基于rsync算法的目的性改进-RexSync
- ecmall源码中的 function _config_view()-关于重写
- python 列表常用操作
- 第13章 Windows内存体系结构
- linux 使用 pyodbc 访问 ms sqlserver 数据库
- php安全设定
- UESTC 1425 Another LCIS
- CSS3弹性盒模型布局模块
- temp-mootools简单语法
- Netty学习笔记(一):接收nodejs模拟表单上传的文件
- linux shell set命令
- 五大理由分析Springboot 2.0为什么选择HikariCP
- mysql 游标的使用方法
- re_test
- 为什么会出现container/injection的思想?
- 知识图谱实战开发案例剖析-番外篇(1)- Neo4j是否支持按照边权重加粗和大数量展示
- 怎样从外网访问内网WebSphere?
- curl请求指定host ip(指定域名解析的内网某ip)
- Redis设置密码重启后失效的解决方案
热门文章
- Awesome Adb——一份超全超详细的 ADB 用法大全【转】
- ap和路由器有什么区别 ap和路由器的区别介绍【图文】
- pkg-config相关
- Java中文&;编码问题小结
- 用mkdirs创建目录
- Spring配置错误 No adapter for IAdvice of type
- codeforces round 421 div2 补题 CF 820 A-E
- bzoj3143游走——期望+高斯消元
- 【旧文章搬运】Windbg+Vmware驱动调试入门(四)---VirtualKD内核调试加速工具
- 【旧文章搬运】Windbg+Vmware驱动调试入门(二)---Vmware及GuestOS的设置