Codeforces 967 贪心服务器分配资源 线性基XOR递增序列构造
A
#include<bits/stdc++.h>
using namespace std;
int dir[][] = {{, -}, {, }, { -, }, {, }};
typedef long long ll;
int n, s;
int h[];
int m[];
int num[];
int getans(int h1, int m1, int h2, int m2)
{
int x1 = (h2 - h1) * ;
int x2 = m2 - m1;
return x1 + x2;
}
int main()
{
//freopen("out.txt", "w", stdout);
cin >> n >> s;
for (int i = ; i <= n; i++)
{
cin >> h[i] >> m[i];
}
if (h[] * + m[] >= + s)
{
cout << << " " << << endl;
return ;
}
for (int i = ; i <= n - ; i++)
{
int now = getans(h[i], m[i], h[i + ], m[i + ]);
if (now >= s * + )
{
m[i]++;
m[i] += s;
while(m[i] >= )
{
m[i] -= ;
h[i]++;
}
cout << h[i] << " " << m[i] << endl;
return ;
}
}
m[n]++;
m[n] += s;
while (m[n] >= )
{
m[n] -= ;
h[n]++;
}
cout << h[n] << " " << m[n] << endl;
}
B
#include<bits/stdc++.h>
using namespace std;
int dir[][] = {{, -}, {, }, { -, }, {, }};
typedef long long ll;
int n;
ll a, b;
ll s[];
ll sum = ;
priority_queue<int, vector<int>, less<int> >que;
int main()
{
//freopen("out.txt", "w", stdout);
cin >> n >> a >> b;
for (int i = ; i <= n; i++)
{
cin >> s[i];
sum += s[i];
if (i != )
{
que.push(s[i]);
}
}
int anser = ;
if (s[]*a >= b * sum)
{
cout << << endl;
return ;
}
int flag = ;
while (flag)
{
sum -= que.top();
que.pop();
anser++;
if (s[]*a >= b * sum)
{
cout << anser << endl;
return ;
}
}
}
C
注意判定同楼层的情况
#include<bits/stdc++.h>
using namespace std;
int dir[][] = {{, -}, {, }, { -, }, {, }};
typedef long long ll;
ll l[];
ll e[];
ll n, m, cl, ce, v;
ll x1, y1, x2, y2;
ll anser = ;
ll addx, addy;
int main()
{
//freopen("out.txt", "w", stdout);
cin >> n >> m >> cl >> ce >> v;
for (int i = ; i <= cl; i++)
{
cin >> l[i];
}
sort(l + , l + cl + );
for (int i = ; i <= ce; i++)
{
cin >> e[i];
}
sort(e + , e + ce + );
int q;
cin >> q;
while (q--)
{
anser = INT_MAX;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2)
{
cout << abs(y1 - y2) << endl;
continue;
}
if (y1 > y2)
{
swap(x1, x2);
swap(y1, y2);
}
addy = abs(x1 - x2);
int now = lower_bound(l + , l + cl + , y1) - l - ;
//cout<<" "<<now<<endl;
int lef = max(now - , );
int rig = min(now + , (int)cl);
//cout << lef << " l1 " << rig << endl;
for (int i = lef; i <= rig; i++)
{
addx = abs(l[i] - y1) + abs(l[i] - y2);
anser = min(anser, addx + addy);
}
now = lower_bound(l + , l + cl + , y2) - l - ;
lef = max(now - , );
rig = min(now + , (int)cl);
//cout << lef << " l2 " << rig << endl;
for (int i = lef; i <= rig; i++)
{
addx = abs(l[i] - y1) + abs(l[i] - y2);
anser = min(anser, addx + addy);
}
addy = abs(x1 - x2) / v;
if (addy * v < abs(x1 - x2))
{
addy++;
}
now = lower_bound(e + , e + ce + , y1) - e - ;
lef = max(now - , );
rig = min(now + , (int)ce);
//cout << lef << " e1 " << rig << endl;
for (int i = lef; i <= rig; i++)
{
addx = abs(e[i] - y1) + abs(e[i] - y2);
anser = min(anser, addx + addy);
}
now = lower_bound(e + , e + ce + , y2) - e - ;
lef = max(now - , );
rig = min(now + , (int)ce);
//cout << lef << " e2 " << rig << endl;
for (int i = lef; i <= rig; i++)
{
addx = abs(e[i] - y1) + abs(e[i] - y2);
anser = min(anser, addx + addy);
}
cout << anser << endl;
}
}
D
卡题意 总共有两个任务 分别需要X1 X2的资源
你有N个服务器 每个服务器上只能运行一个任务 但是你可以把任务平分到几个服务器上运行 问你能不能完成这两个任务
肯定先排序 然后这两个任务各所在的服务器肯定是连续的一段
预处理出每个任务分成i份所需要的资源 枚举哪个任务所在服务器是前面的 然后再枚举这个任务分成几份 check第二个任务是否能满足
能满足就输出
#include<bits/stdc++.h>
#define maxn 300005
using namespace std;
int a[maxn], b[maxn], c[maxn], id[maxn], n;
void solve1()
{
for (int i = n - ; i > ; i--)
{
int p = lower_bound(c + , c + n + , a[i]) - c; //如果选x1作为前面连续的一部分 分为i份所需要开始的最前位置
int ps = p + i - ; //分成i份后的末尾部分
if (ps < n && b[n - ps] <= c[ps + ]) //如果作为前面一部分成立 并且把x2分成n-ps份后所需的资源数小于c[ps+1] 整体成立
{
puts("Yes");
printf("%d %d\n", i, n - ps);
for (int i = p; i <= ps; i++)
{
printf("%d ", id[i]);
}
puts("");
for (int i = ps + ; i <= n; i++)
{
printf("%d ", id[i]);
}
exit();
}
}
}
void solve2() //作用同上
{
for (int i = n - ; i > ; i--)
{
int p = lower_bound(c + , c + n + , b[i]) - c, ps = p + i - ;
if (ps < n && a[n - ps] <= c[ps + ])
{
puts("Yes");
printf("%d %d\n", n - ps, i);
for (int i = ps + ; i <= n; i++)
{
printf("%d ", id[i]);
}
puts("");
for (int i = p; i <= ps; i++)
{
printf("%d ", id[i]);
}
exit();
}
}
}
bool cmp(const int &A, const int &B)
{
return c[A] < c[B];
}
int main()
{
int x1, x2;
scanf("%d%d%d", &n, &x1, &x2);
for (int i = ; i <= n; i++)
{
scanf("%d", &c[i]), id[i] = i;
}
sort(id + , id + n + , cmp); //相当于sort piar<int,int>
sort(c + , c + n + );
for (int i = ; i <= n; i++)
{
a[i] = x1 / i + (x1 % i > ), b[i] = x2 / i + (x2 % i > );
//a[i] 表示如果x1平均分为i个所需要的资源数
//b[i] 表示如果x2平均分为i个所需要的资源数
}
solve1();
solve2();
puts("No");
return ;
}
E
Codeforces 967 贪心服务器分配资源 线性基XOR递增序列构造的更多相关文章
- Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理
https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...
- Codeforces 1299D - Around the World(线性基+图论+dp)
Codeforces 题目传送门 & 洛谷题目传送门 一道线性基的综合题 %%%%%% 首先注意到"非简单路径""异或和"等字眼,可以本能地想到线性基. ...
- 【bzoj3105】【cqoi2013】【新Nim游戏】【线性基+贪心】
Description 传统的Nim游戏是这种:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量能够不同).两个游戏者轮流操作,每次能够选一个火柴堆拿走若干根火柴.能够仅仅拿一根,也能够拿走整堆火柴 ...
- 高斯消元 & 线性基【学习笔记】
高斯消元 & 线性基 本来说不写了,但还是写点吧 [update 2017-02-18]现在发现真的有好多需要思考的地方,网上很多代码感觉都是错误的,虽然题目通过了 [update 2017- ...
- [HAOI2017]八纵八横 线性基
题面 题面 题解 观察到题目中的 "内陆经济环" 不好处理,因此我们把它拆成 "内陆经济链". 对于1号节点,我们创建一个它的复制节点n + 1号节点,这个节点 ...
- P4570 [BJWC2011]元素 (线性基)
题意:n个石头 每个石头有a,b两个属性 要求选出一些石头使得没有一个子集的a属性xor和为0 且b属性和最大 题解:线性基例题了.. 好像需要理解一些性质 1.原序列里任一数都可有由线性基xor得到 ...
- Codeforces 1100F(线性基+贪心)
题目链接 题意 给定序列,$q(1\leq q \leq 100000) $次询问,每次查询给定区间内的最大异或子集. 思路 涉及到最大异或子集肯定从线性基角度入手.将询问按右端点排序后离线处理询问, ...
- CodeForces - 1100F:Ivan and Burgers (线性基&贪心)(离线 在线)
题意:给定N个数,Q次询问,求区间最大异或和. 思路:一开始想的线性基+线段树.单次线性基合并的复杂度为20*20,结合线段树,复杂度为O(NlogN*20*20):显然,超时. 超时代码: #inc ...
- LOJ 6060「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set(线性基,贪心)
LOJ 6060「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set $ solution: $ 这一题的重点在于优先级问题,我们应该先保证总和最大,然后再保证某一个最小.于是我 ...
随机推荐
- android 给控件使用自定义字体Typeface
第一步:将字体资源放在assets 资源文件夹下: 第二步:获取字体资源 Typeface mTf = Typeface.createFromAsset(c.getAssets(), "Op ...
- Slider 滑块
通过拖动滑块在一个固定区间内进行选择 ¶基础用法 在拖动滑块时,显示当前值 通过设置绑定值自定义滑块的初始值 <template> <div class="block&qu ...
- 禁止在DBGrid中按delete删除记录
procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin if (ssctr ...
- UML_2_浅谈UML的概念和模型之UML九种图
转载:https://my.oschina.net/zhumenzhongren/blog/667353 上文我们介绍了,UML的视图,在每一种视图中都包含一个或多种图.本文我们重点讲解UML每种图的 ...
- CSS3 长度单位
http://www.w3chtml.com/css3/units/length/vh.html https://www.html.cn/book/css/values/length/vh.htm . ...
- python学习之模块-模块(五)
5.10 包 5.10.1 包的概念 [官网解释] Packages are a way of structuring Python's module namespace by using " ...
- LeetCode.1021-删除最外面的括号(Remove Outermost Parentheses)
这是小川的第380次更新,第408篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第242题(顺位题号是1021).有效的括号字符串为空(""),&qu ...
- Excel透视表进阶之排序、筛选、分组、总计与分类汇总
排序 自动排序 升序: 数字(从小到大) 日期(日期越早越靠小) 英文(按照A-Z) 中文(按照拼音的A-Z) 手动排序 通过鼠标的拖拽来完成手动排序 通过快捷菜单的方式:右击-移动 依据其他字段进行 ...
- 服务器被植入木马,CPU飙升200%
线上服务器用的是某云的,欢快的完美运行着Tomcat,MySQL,MongoDB,ActiveMQ等程序.突然一则噩耗从前线传来:网站不能访问了! 此项目是我负责,我以150+的手速立即打开了服务器, ...
- 赛道修建 NOIP 2018 d1t3
题目大意 最小值最大 考虑二分 二分答案 判断能不能构成m条路径 很明显满足单调性 可行 思考如何判断 对于一个节点 它的儿子会传上来一些路径 这些路径只有三种处理方式 一.传上去(只能传一条) 二. ...