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,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 贪心的更多相关文章
- 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. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
- 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].让你最小化每天比海平面低的痕迹条数之和. ...
- 【推导】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 ...
随机推荐
- 【CS231N】4、神经网络
一.疑问 二.常用激活函数 1. Sigmoid sigmoid将输入实数值"挤压"到0到1范围内.更具体地说,很大的负数变成0,很大的正数变成1.它对于神经元的激活频率有良好 ...
- php 把数字转化为大写中文
PHP 数字转大写中文 PHP入门小菜鸟一枚.下午要求写一个把数字转成大写中文的脚本,百度了一波,几十个博客和网站都是用的那四个代码,第一个运行不了,第二个有问题,不合要求,第三个第四个太长,懒得看, ...
- 13_Java面向对象_第13天(static、final、匿名对象、内部类、包、修饰符、代码块)_讲义
今日内容介绍 1.final 关键字 2.static 关键字 3.匿名对象 4.内部类 5.包的声明与访问 6.访问修饰符 7.代码块 01final关键字概念 A: 概述 继承的出现提高了代码的复 ...
- Gradle入门(6):创建Web应用项目
如果要用 Java 和 Gradle 创建一个 Web 应用项目,我们首先需要创建一个 Java 项目,下面来看看该如何去做. 创建Java项目 我们可以使用Java插件创建一个Java项目,通过添加 ...
- [转]无需看到你的脸就能认出你——实现Beyond Frontal Faces: Improving Person Recognition Using Multiple Cues
转自:http://www.cnblogs.com/sciencefans/p/4764395.html
- JavaScript本地存储实践(html5的localStorage和ie的userData)
http://www.css88.com/archives/3717 JavaScript本地存储实践(html5的localStorage和ie的userData) 发表于 2011年06月11日 ...
- iOS 企业账号申请证书和打包ipa
准备: 299美元的企业账号. 1.登陆苹果开发者中心: https://developer.apple.com .点击Menber Center.输入企业账号和密码登陆. 2.登陆后选择“Certi ...
- NOI前训练日记
向别人学习一波,记点流水帐.17.5.29开坑. 5.29 早晨看了道据说是树状数组优化DP的题(hdu5542),然后脑补了一个复杂度500^3的meet in the middle.然后死T... ...
- 字典树(trie树)的指针简单实现pascal
问题1:给你一个单词集合,支持添加,删除,询问某个单词出现次数. ; maxn=; type dictree=^rec; rec=record next:array[..maxword]of dict ...
- 【codeforces 528D】 Fuzzy Search
http://codeforces.com/problemset/problem/528/D (题目链接) 题意 给定母串和模式串,字符集大小为${4}$,给定${k}$,模式串在某个位置匹配当且仅当 ...