【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源。有n个服务器来提供资源,第i台能提供a[i]的资源。当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担给它们,要求每台服务器承担的资源需求不超过其所能提供的资源需求。给定一种合法的方案,每台服务器要么没有被分配给任何一个服务,或者被分配给其中一个服务。
对服务器按能提供的资源从小到大排序。枚举给S1分配的服务器数量i,然后在a数组中二分,就可以得到给S1提供的是哪i台服务器,它们占据了a数组中连续的一段。
然后给S2哪些呢?分两种情况:①倘若a数组最后存在k台能满足S2,并且这k台不与给S1的相交,那么不妨就给它这最后的k台。
②倘若这i台之后,不存在a的某个后缀能够满足S2,那么预处理一个东西:pre[i]代表(n-i+1)-need[i](倘若要使用第i台那么至少要使用的总台数),然后对这个玩意求个前缀max,如果S1的i台前存在某个位置j,能使得pre[j]>=i,就是说j所对应的能空出来的台数大于等于S1占据掉的台数,那么不妨从第n台,倒着数need[j]台(跳过S1的i台),分配给S2即可。
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct data{
int val,pos;
data(){}
data(const int &val,const int &pos){
this->val=val;
this->pos=pos;
}
};
bool cmp(const data &a,const data &b){
return a.val!=b.val ? a.val<b.val : a.pos<b.pos;
}
int n,m1,m2;
data a[300005];
int premax[300005],premaxpos[300005],need[300005];
int main(){
//freopen("d.in","r",stdin);
scanf("%d%d%d",&n,&m1,&m2);
for(int i=1;i<=n;++i){
scanf("%d",&a[i].val);
a[i].pos=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;++i){
int tmp;
if(m2%a[i].val==0){
tmp=m2/a[i].val;
}
else{
tmp=m2/a[i].val+1;
}
if((n-i+1)-tmp>premax[i-1]){
premax[i]=(n-i+1)-tmp;
premaxpos[i]=i;
need[i]=tmp;
}
else{
premax[i]=premax[i-1];
premaxpos[i]=premaxpos[i-1];
need[i]=need[i-1];
}
}
int hou=0;
for(int i=n;i>=1;--i){
if(m2<=(ll)a[i].val*(ll)(n-i+1)){
hou=i;
break;
}
}
if(!hou){
puts("No");
return 0;
}
for(int i=1;i<=n;++i){
int tmp;
if(m1%i==0){
tmp=m1/i;
}
else{
tmp=m1/i+1;
}
data *p=lower_bound(a+1,a+n+1,data(tmp,0),cmp);
if(p-a+i-1>n){
continue;
}
if(hou>=p-a+i){
puts("Yes");
printf("%d %d\n",i,n-hou+1);
for(int j=p-a;j<p-a+i;++j){
printf("%d%c",a[j].pos,j==p-a+i-1 ? '\n' : ' ');
}
for(int j=hou;j<=n;++j){
printf("%d%c",a[j].pos,j==n ? '\n' : ' ');
}
return 0;
}
else if(premax[p-a-1]>=i){
puts("Yes");
printf("%d %d\n",i,need[p-a-1]);
for(int j=p-a;j<p-a+i;++j){
printf("%d%c",a[j].pos,j==p-a+i-1 ? '\n' : ' ');
}
int cnt=0;
for(int j=n;j>=1;--j){
if(j>=p-a && j<p-a+i){
continue;
}
++cnt;
printf("%d%c",a[j].pos,cnt==need[p-a-1] ? '\n' : ' ');
if(cnt==need[p-a-1]){
break;
}
}
return 0;
}
}
puts("No");
return 0;
}
【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution的更多相关文章
- Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) F 构造
http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义: ...
- Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心
http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问, ...
- Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心
http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...
- 【推导】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) B. Mystical Mosaic
题意:给你一个棋盘的最终局面. 你的一次操作可以选择一些行和列,将它们的交叉点染黑,不能重复选择某行或者某列.问你是否能经过数次操作之后,达到目标局面. 就枚举所有黑点,如果该点行列都没被标记,就给它 ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)
A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep
http://codeforces.com/contest/948/problem/A A. Protect Sheep Bob is a farmer. He has a large pastu ...
- Codeforces Round #470 (rated, Div. 1, based on VK Cup 2018 Round 1) 923D 947D 948E D. Picking Strings
题: OvO http://codeforces.com/contest/947/problem/D 923D 947D 948E 解: 记要改变的串为 P1 ,记目标串为 P2 由变化规则可得: ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow
题目链接 题意 每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...
- 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio
题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...
随机推荐
- tensorflow环境安装
tensorflow环境安装1.安装虚拟机Virtrualbox下载地址:https://www.virtualbox.org/wiki/Downloads 2.下载安装Ubuntu镜像下载地址:ht ...
- sql_injection之基本get注入
1.代码篇 <?php error_reporting(0); include("../conn.php"); if(isset($_GET['id'])){ $id=$_G ...
- C# 序列化高级用法
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- vs2010,vs2012注释快捷键
注释:VS2010是(Ctrl+E,C),VS2012是(Ctrl+K, Ctrl+C) 反注释:VS2010是(Ctrl+E,U),VS2012是(Ctrl+K, Ctrl+U)
- Prepare tasks for django project deployment.md
As we know, there are some boring tasks while deploy Django project, like create db, do migrations a ...
- SQLAlchemy-介绍安装
一:概述 SQLAlchemy的SQL工具包和对象关系映射是一个全面的工具集,用来处理数据库和Python. 它有几个不同的功能领域,可以单独使用或组合使用. 所示的主要组件,组件依赖关系组织成层: ...
- yum命令安装软件时,出现--centos 7 安装apache 出现 Could not resolve host: mirrorlist.centos.org; 未知的错误"--CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决
CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决 今天在虚拟机上安装完CentOS6.5之后,首次使用时yum命令安装软件时,出现 ...
- 列表CListCtrl类使用
CListCtrl是列表控件类,列表控件的每一行叫做一个item,每一列叫做一个subitem.每一行和每一列都有个ID号,可以确定唯一的单元格. 最近使用了这个控件,有心得总结如下: (Dialog ...
- SQL中EXCEPT和Not in的区别?
初始化两张表: CREATE TABLE tb1(ID int) INSERT tb1 SELECT NULLUNION ALL SELECT NULLUNION ...
- MySQL学习笔记:like和regexp的区别
一.like关键字 like有两个模式:_和% _:表示单个字符,用来查询定长的数据 select name from table where name like '陈__'; %:表示0个或多个任意 ...