Resource Distribution (思维+贪心好题)

【信息科学与工程学】计算机科学与自动化-——第十五篇云计算 11 算法篇 在百万级虚拟机、百万级租户的超大规模云环境中,核心算法挑战包括:挑战维度具体问题算法需求技术复杂度规模性​百万级对象并发管理分布式算法、分区算法极高(NP-hard问题)多租户​租户间隔离与资源共享公平性算法、隔离算法高(多目标优化)动态性​资源需求实时变化自适应算法、在线算法高(实时决策)异构性​硬件/负载/需求差异分类算法、匹配算法中高(多维度优化)经济性​资源利用率与成本平衡优化算法、博弈论算法高(多目标博弈)以下是按领域分类的详细算法列表:算法名称数学建模表达核心思想时间复杂度适用场景推理步骤首次适 阅读详情

Resource Distribution

One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number cj

of artificial resource units.

In order for production to work, it is needed to deploy two services S1

and S2 to process incoming requests using the servers of the department. Processing of incoming requests of service Si takes xi

resource units.

The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service Si

is deployed using ki servers, then the load is divided equally between these servers and each server requires only xi/ki

(that may be a fractional number) resource units.

Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.

Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.

Input

The first line contains three integers n

, x1, x2 ( 2≤n≤300000, 1≤x1,x2≤109

) — the number of servers that the department may use, and resource units requirements for each of the services.

The second line contains n

space-separated integers c1,c2,…,cn ( 1≤ci≤109

) — the number of resource units provided by each of the servers.

Output

If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).

Otherwise print the word "Yes" (without the quotes).

In the second line print two integers k1

and k2 ( 1≤k1,k2≤n

) — the number of servers used for each of the services.

In the third line print k1

integers, the indices of the servers that will be used for the first service.

In the fourth line print k2

integers, the indices of the servers that will be used for the second service.

No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.

Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note

In the first sample test each of the servers 1, 2 and 6 will will provide 8/3=2.(6)

resource units and each of the servers 5, 4 will provide 16/2=8

resource units.

In the second sample test the first server will provide 20

resource units and each of the remaining servers will provide 32/3=10.(6) resource units.

网上一篇博客写的很好,很清晰直接载过来了

思路传送门

两遍贪心

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 3e5+100;
struct node{
    int c;
    int id;
    bool operator < (const node &other)const{
        return c > other.c;
    }
}s[maxn];
int main(){
    int n,x1,x2;
    int k1,k2;
    int c[maxn];
    cin >> n >> x1 >> x2;
    for(int i = 1; i <= n; i++){
        cin >> s[i].c;
        s[i].id = i;
    }
    sort(s+1,s+1+n);//从大到小排序
    //尝试先分配X1再分配X2
    for(int i = 1; i <= n; i++){
        //以服务器i为下限组成X1需要的钱K1个
        k1 = x1 / s[i].c;
        if(x1 % s[i].c != 0) k1++;//算出以ci为最小值需要的最少数量
        if(k1 >= i) continue; // 如果往前的总数量不够这个最小数量继续寻找,虽然对于X1来说等于是可以的,但是如果等于就没办法给X2分配了,所以仍然要继续下一次寻找
        //否则给X2分配
        k2 = x2 / s[i-k1].c;
        if(x2 % s[i-k1].c != 0) k2++;
        if(k2 > i - k1) continue; //这次直接大于就行了
        //分配成功
        printf("Yes\n%d %d\n",k1,k2);
        for(int j = i-k1+1; j <= i; j++){
            printf("%d%c",s[j].id,j == i ? '\n' : ' ');
        }
        for(int j = i-k1-k2+1; j <= i-k1; j++){
            printf("%d%c",s[j].id,j == i-k1 ? '\n' : ' ');
        }
        return 0;
    }
    //先分配X2原理同上不在赘述
    for(int i = 1; i <= n; i++){
        k2 = x2 / s[i].c;
        if(x2 % s[i].c != 0) k2++;
        if(k2 >= i) continue;
        k1 = x1 / s[i-k2].c;
        if(x1 % s[i-k2].c != 0) k1++;
        if(k1 > i - k2) continue;
        printf("Yes\n%d %d\n",k1,k2);
        for(int j = i-k2-k1+1; j <= i-k2; j++){
            printf("%d%c",s[j].id,j == i-k2 ? '\n' : ' ');
        }
        for(int j = i-k2+1; j <= i; j++){
            printf("%d%c",s[j].id,j == i ? '\n' : ' ');
        }
        return 0;
    }
    printf("No\n");
    return 0;
}


【信息科学与工程学】【运营科学】第二篇 C4信息与通信网络运营 (C4) ——数据中心网络运营04 典型值:λ1​∈[−0.02,−0.01], λ2​∈[−0.01,0], η1​,η3​∈[0.1,0.3], η2​,η4​∈[0.05,0.15]参数:δ1​∈[−0.8,−0.3], δ2​∈[−0.5,−0.2], δ3​∈[−0.4,−0.1], δ4​∈[−0.6,−0.2]参数:φ1​∈[0.1,0.3], φ2​∈[−0.2,−0.05], φ3​∈[−0.1,0.1], φ4​∈[−0.3,−0.1]参数:α∈[0.3,0.6], β∈[0.2,0.4], γ∈[0.01,0.03] 阅读详情

相关推荐

【信息科学与工程学】【安全领域】第一百四十二篇 零信任网络解决方案中的算法04

对于节点 i, 有功和无功功率平衡方程为: Pi​=Vi​∑j=1N​Vj​(Gij​cosθij​+Bij​sinθij​), Qi​=Vi​∑j=1N​Vj​(Gij​sinθij​−Bij​cosθij​)。下风向某点 (x,y,z)的浓度 C为: C=2πuσy​σz​Q​exp(−2σy2​y2​)[exp(−2σz2​(z−H)2​)+exp(−2σz2​(z+H)2​)], 其中 Q是源强, u是风速, H是有效源高, σy​,σz​是水平和垂直扩散参数。

weixin_49199313的博客 1409

codeforces 967 D Resource Distribution

短板*数量,选好短板以后就只关心数量。遍历短板的位置,并在大于短板的范围寻找可能的解

toby的博客 647

TC8测试TCP-UNACCEPTABLE-04/006

TC8测试TCP-UNACCEPTABLE-04/006

Resource Distribution

贪心

a free man 750

告别数据丢失焦虑:用Python手把手实现Reed-Solomon码(附完整代码)

本文详细介绍了如何使用Python实现Reed-Solomon纠错码(RS码),帮助开发者有效防止数据丢失。通过基础编解码实战、文件保护方案和高级性能优化技巧,读者可以轻松掌握这一前向纠错技术,应用于物联网、文件存储和网络传输等场景,提升数据可靠性。

weixin_42527160的博客 222

Veristand simulink 集成 simulink 非正版如何处理

1、安装 veristand model Generation Support add-on。matlab 安装veristand model support 记录。下载 以后 如果非正版matlab 直接拖命令行执行。下载后直接命令行执行即可。

flik9527的博客 598

贪心心得及例题思路

贪心,顾名思义,是获取利益并且是持续的。记住一句话“局部大于全局”,贪心不讲究对于整体来说是最优的,而只是对于此阶段的最优情况。所以贪心并不一定适用于所有情况,例如完整的背包问题,但依旧可以解决‘部分背包问题’。以下举例三种问题来详细讲解贪心思想。

weixin_70600848的博客 761

基于Simulink的二相混合式步进电机驱动器快速建模与仿真实践

本文详细介绍了如何利用Simulink对二相混合式步进电机驱动器进行快速建模与仿真。通过从零搭建电机数学模型、设计H桥控制逻辑,并集成步进时序,手把手指导读者创建可运行的仿真模型文件。该方法能有效验证控制策略,避免硬件调试风险,是学习与实践电机驱动开发的理想途径。

weixin_29171087的博客 147

Codeforces 967 D. Resource Distribution

D. Resource Distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne department of some software company has nn servers of different specif...

maxdumbledore的博客 468

避坑指南:SAP成本中心分割结构配置常见错误及解决(含KA06/KL01前置步骤)

本文深入解析了SAP成本中心会计中分割结构配置的关键步骤与常见错误。重点强调了配置前必须通过KA06创建次级成本要素(类别42)和通过KL01创建活动类型这两个核心前置步骤,并详细剖析了在OKES中定义分割规则及版本时的高频报错原因与解决方案,帮助顾问和运维人员有效规避配置陷阱,确保成本分摊的准确性。

pear55的博客 865

微信小程序转发功能异常报错 由于小程序违规分享功能暂时无法使用的解决办法

小程序右上角转发功能被封,不代表你违规了,而可能是你没认证、没备案!很多功能都是“先合规、后开发”,踩坑就晚了,别像我一样绕了三圈才发现问题。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 2606

Codeforces 976D - Resource Distribution(贪心 + 二分)

题目链接 http://codeforces.com/contest/967/problem/D 题目大意 能否用n个服务器同时为两个任务分配资源。 用k个服务器分配任务量为S的任务时,占用每个服务器S/k1的资源。 每个服务器只能分配到一个任务。 解题思路 降维,优先将大额服务器分配给一个任务,再枚举另一个任务需要的服务器数。 比如,优先将k1个大额的服务...

Hrbust_cx的博客 520

基于STM32L4XX、HAL库的ICP-10111压力传感器驱动程序设计

define ICP10111_CMD_MEAS_ULN 0x7866 // 超低噪声模式。#define ICP10111_CMD_MEAS_LP 0x609C // 低功耗模式。#define ICP10111_CMD_MEAS_LN 0x70DF // 低噪声模式。#define ICP10111_CMD_MEAS_N 0x6825 // 正常模式。ICP10111_MODE_LN, // 低噪声。// 等待测量完成(根据模式不同等待时间不同)

zhusl6688的博客 416

Codeforces Round #410 (Div. 2) D. Mike and distribution 思维

D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking abou

jerans的博客 608

从DDPM到DDIM:深入解读《Denoising Diffusion Implicit Models》

DDIM发表在ICRL2021上,是DDPM重要的改进之一,能显著提高DDPM的样本质量、减少采样时间,并且能显式控制插值,已经被广泛应用到现在的Diffusion Models上。这篇博客和大家一起详细解读一下DDIM,认识这一伟大的模型。.........

沉迷单车的追风少年 1万+

vivo X200 Ultra前瞻系列(1):重塑影像旗舰标准

在色彩风格化、视频专业度上实现了安卓阵营的突破性进步。其2亿像素长焦、双LYT-818传感器及5轴防抖技术,对追求个性化创作的用户具有强吸引力。若真机表现能兑现硬件承诺,X200 Ultra有望重新定义手机影像的“专业”标准。然而,其厚重设计、价格门槛及生态适配问题,仍需市场检验。vivo X200 Ultra作为2025年上半年影像旗舰,以“全焦段夜视仪+电影级视频”为核心卖点,主打。,对标小米15 Ultra、OPPO Find X8 Ultra等竞品。,顶配版(24GB+2TB)逼近万元。

专注:太空算力、AI infra、异构调度、大模型成本工程 963

codeforcese 477 D.Resource Distribution

D. Resource Distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne department of some software company has nn servers of different specif...

~不可描述~ 418

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

CodeFroces 873B. Balanced Substring(思维题)

点击打开链接 题意:给出一个字符串,求其中满足0和1的个数相等的最长字符串的长度。 解法:当时只能想到枚举区间然后直接用前缀和判定的方法,但是枚举区间复杂度明显不对。 然后想到了二分,发现很多数据都挺对的,然后wa24。想了想发现,有可能4不满足但是6满足,故不存在单调性。。。 最后看了一发题解。每位有一个值:前i个数字0的个数 - 前i个数字1的个数。如果有两个地方的值是相同的,那么显然

llzhh的博客 402

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

C - Greedy Arkady-(贪心思维题-)

C - Greedy Arkady  CodeForces - 965C  #include&lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; ll n,m,k,d; ll l; ll ans; int main() { cin&gt;&gt;n&gt;&gt;k&gt;&gt;m&gt;&gt;d; ...

BePosit的博客 388

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

CF967D Resource Distribution

思路: 在一堆服务器中,资源最少的那一个是“瓶颈”,由此想到贪心思路。 首先对所有服务器按照资源数量c排序,再从头到尾扫描。对每个位置,根据x1和x2计算出两段连续的服务器集合分别分配给A任务和B任务(还需要枚举分配A和B的先后顺序),如果够用,则有解。所有位置都不行,则无解。 实现: 1 #include <bits/stdc++.h> 2 using namesp...

weixin_30443895的博客 155

Codefroces 485C Bits【贪心+思维】好题

C. Bits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let's denote as the number of bits set ('1' bits) in the bina

mengxiang000000 472

CF 967D. Resource Distribution 暴力,二分

题意:n个服务器 第i个服务器最多能负载a[i]单元.现在有两个任务其值为s1,s2 若有一个任务值为S,分给k个服务器 则这k个服务器其a[i]值>=(S+k-1)/k   每台服务器最多运行一个任务.问任务s1,s2是否能通过这n个服务器运行起来. n 枚举任务1要用到x台服务器,那么这x台中最小的为val=(s1+x-1)/x  在a二分找到第一个>=val的下标i,此

noone0的博客 404

poj 1989 & hdu 2712 & 洛谷5093 题解(贪心,思维,好题)

原题链接: poj hdu 洛谷 题意简述 给定一个序列,长度为n(&lt;=1e5)n(&lt;=1e5)n(<=1e5),所有数都在[1,k][1,k][1,k]范围内。请你在序列中找到一个长度最短的没有出现的子序列(不一定连续的那种)。 思路 题解里面有个奆佬是这么说的: 我们把原序列分组(一组是一段连续的子序列),一个组里包含[1,k][1,k][1,k]中的所有数...

LightningUZ的博客 345

贪心算法题集总结

有一篇很好的贪心算法入门文章跟大家分享: http://blog.csdn.net/qq_32400847/article/details/51336300 可以看完这篇文章再去做题 这里我主要总结一下自己最近做贪心题目的情况: 从上个月7号开始吧,我就开始刷贪心的题了,其中不乏有些难度很高的题(对于我这菜鸟而言),百思不得其解后看了解题报告,但是也让我学到了很多...

zark721的博客 5001

贪心 暴力 思维题 (持续更新Ing)

前言: 这里面的题目都是对大佬比较简单的题目qwq 大佬们轻喷~ 牛牛的朋友 这个贪心思路我真的i了 第一次遇到这样的贪心 觉得思路真的很巧妙qwq 所以分享一波 首先对所有的牛排序一波 然后枚举分界点 分界点左边向右移 分界点右边向左移 然后排序 更新其中的最小值 #include<bits/stdc++.h> using namespace std; const i...

JCC 408

poj1017 贪心 思维 好题

题意:运输公司有6种规格的物品各若干件:1*1 , 2*2,3*3 ,4*4,5*5,6*6的,这六种物品都要放在6*6的箱子里运输,让你求出最少用多少个箱子。 解题思路:有两种方法来做,第一种特别繁琐,也是最直接的解决方式,那就是根据常识来贪心并模拟,代码量很大,另一种和这个贪心一个思路,实现的时候非常简便,下面是贪心的大致思路: 6*6的只能用单独的箱子来放;

练练大脑,有何不好 1204
上一篇: Watering System (模拟,水题)
下一篇: Battleship (模拟)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值