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: $ 这一题的重点在于优先级问题,我们应该先保证总和最大,然后再保证某一个最小.于是我 ...
随机推荐
- 初始化EPT
struct eptp_bits { unsigned memory_type :; /* 0: UC uncacheable, 6: WB writeback */ unsigned pagewal ...
- Android 中布局的优化措施都有哪些?
1.尽可能减少布局的嵌套层级可以使用 sdk 提供的 hierarchyviewer 工具分析视图树,帮助我们发现没有用到的布局.2.不用设置不必要的背景,避免过度绘制比如父控件设置了背景色,子控件完 ...
- 代码实现:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据 (包括学生号,姓名,三门课成绩),计算出平均成绩,将原有的数据和计算出的平均分数存放在磁盘文件"stud"中。
import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.ut ...
- 趣谈linux操作系统笔记-内核初始化
内核的启动从入口函数 start_kernel() 开始.在 init/main.c 文件中,start_kernel 相当于内核的main 函数.打开这个函数,你会发现,里面是各种各样初始化函数 X ...
- Go语言程序结构
注意:Go语言源码文件编码格式必须是 UTF-8 格式,否则会导致编译器出错. 1.语言变量 a) 指定变量类型,声明后若不赋值,使用默认值. var name string b) 根据值自行判定变量 ...
- flutter ListView列表和导航传值以及回调
main.dart import 'package:flutter/material.dart'; void main(){ return runApp(MyApp()); } class Produ ...
- redis源码分析之数据结构--dictionary
本文不讲hash算法,而主要是分析redis中的dict数据结构的特性--分步rehash. 首先看下数据结构:dict代表数据字典,每个数据字典有两个哈希表dictht,哈希表采用链式存储. typ ...
- Python 的列表生成器
列表生成器为创建列表提供了一种简洁的方式. 比如说,我们可以这样实现一个平方数列表 squares=[x**2 for x in range(10)] 或者这样迭代一个字符串来生成列表 >> ...
- bootstrap select2控件
- cocos2dx基础篇(5) 按钮
这篇是直接复制的别人的,太多了,难得写... [本节内容] CCMenu.CCMenuItem其具体的六个子类 [菜单CCMenu] 菜单CCMenu是用来装载菜单按钮的图层,图层中的子节点只能够是菜 ...