http://codeforces.com/contest/967/problem/D

题目大意:

有n个服务器,标号为1~n,每个服务器有C[i]个资源。现在,有两个任务需要同时进行,令他为x1,x2.

运行任务的条件:

①每个服务器只能同时运行一个任务

②任务可以同时分配到多个服务器中执行。假设任务x1分配到a个服务器中,则每个服务器都需要使用x1/a的资源(该资源可以为小数)

问能否满足以上条件,使得x1,x2同时在服务器中运行?

思路:

将所有服务器按照资源增序排列,定义dp(i)表示从第i个服务器到第n个服务器的资源提供量, 即dp[i] = (n - i + 1) * c[i];

接下来,暴力一遍1~n,

在满足dp(i)>=x1的时候,就贪心的取最少的满足c(i) * cnt >= x1

然后再利用dp去找满足x2的条件即可。

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 1e6 + ;
int n, x1,x2;
vector<pair<int, int> > ve;
int dp[maxn];
pair<int, int> ans1, ans2; bool check(int i, int x1, int x2){
int cnt1 = x1 / ve[i].fi;
if (x1 - cnt1 * ve[i].fi > ) cnt1++;
if (dp[i + cnt1] >= x2) {
ans1 = mk(i, i + cnt1 - );
ans2.fi = i + cnt1;
int cnt2 = x2 / ve[i+cnt1].fi;
if (x2 - cnt2 * ve[i+cnt1].fi > )
cnt2++;
ans2.se = ans2.fi + cnt2 - ;
return true;
}
return false;
} bool solve(){
bool flag = false;
for (int i = ; i < ve.size(); i++){
if (dp[i] >= x1){
if (check(i, x1, x2)) flag = true;
}
}
if (flag == false){
swap(x1, x2);
for (int i = ; i < ve.size(); i++){
if (dp[i] >= x1){
if (check(i, x1, x2)) {
flag = true;
swap(ans1, ans2);
}
}
}
}
if (flag){
puts("Yes");
printf("%d %d\n", ans1.se - ans1.fi + , ans2.se - ans2.fi + );
for (int j = ans1.fi; j <= ans1.se; j++)
printf("%d ", ve[j].se);
cout << endl;
for (int j = ans2.fi; j <= ans2.se; j++)
printf("%d ", ve[j].se);
cout << endl;
return true;
}
return false;
} int main(){
cin >> n >> x1 >> x2;
for (int i = ; i <= n; i++){
int a; scanf("%d", &a);
ve.pb(mk(a, i));
}
sort(ALL(ve));
for (int i = ve.size()-; i >= ; i--){
dp[i] = (ve.size() - i) * ve[i].fi;
}
if (solve() == false) puts("No");
return ;
}

Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心的更多相关文章

  1. 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条路目前开启(即能走),剩下的都是关闭状态 定义: ...

  2. 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), 问, ...

  3. 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

    题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...

  4. 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 ...

  5. 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  由变化规则可得: ...

  6. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow

    题目链接  题意  每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...

  7. 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio

    题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...

  8. 【推导】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) B. Mystical Mosaic

    题意:给你一个棋盘的最终局面. 你的一次操作可以选择一些行和列,将它们的交叉点染黑,不能重复选择某行或者某列.问你是否能经过数次操作之后,达到目标局面. 就枚举所有黑点,如果该点行列都没被标记,就给它 ...

  9. 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 ...

随机推荐

  1. 第一次spring冲刺第5天

    今天进行讨论基础功能的核心代码方面,还有简单的讨论继续关于界面的美化, 计算生成的答案功能 public class Core {// char[]h={'+','-','*','/'};int re ...

  2. vue router 几种方式对比 (转载)

    <div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 router-link 组件来导 ...

  3. [转帖]TLS 版本问题

    转帖 From https://www.cnblogs.com/xjnotxj/p/7252043.html 一.环境: CentOS 6.8nginx 1.6.0php 7.0.10 二.背景 最近 ...

  4. 检查cpu是否支持VT-X(HAXM)

    可以使用CPU-Z进行检测,CPU是否支持VT-X,如果不支持,就不要浪费时间安装HAXM了. 可以试一下Genymotion模拟器.

  5. Java-JDBC.mysql 工具类 读取本地文件配置

    引用 mysql-connector-jav 的jar 配置文件为  database.propertties .  格式如下 driverClass=com.mysql.jdbc.Driver ur ...

  6. screen.height && screen.width

    screen.height && screen.width how to get window max width in js screen.height; screen.width; ...

  7. UVA11248_Frequency Hopping

    给一个有向网络,求其1,n两点的最大流量是否不小于C,如果小于,是否可以通过修改一条边的容量使得最大流量不小于C? 首先对于给定的网络,我们可以先跑一遍最大流,然后先看流量是否大于C. 然后保存跑完第 ...

  8. python自动化之图像

    ''' RGBA值:指定颜色中的红.绿.蓝和alpha(透明度)的值 RGBA                                            名称 (255,255,255,2 ...

  9. iOS 代码片段的添加!

    说明.代码片段就是方便快捷输入的片段,类似do -while.switch等这些系统语句,这些系统的语句也是代码片段,快速输入一些常用的代码语句,就可以把这些语句写成代码片段! Example: 我们 ...

  10. 【原创】centos6创建sftp账号,并设置权限和目录

    网上找了个教程,折腾好长时间都不行,最后往死里整,终于弄好了,记录一下. 系统环境:Centos6.9 64bit 完美解决: Permission denied (publickey,gssapi- ...