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递增序列构造的更多相关文章

  1. Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理

    https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...

  2. Codeforces 1299D - Around the World(线性基+图论+dp)

    Codeforces 题目传送门 & 洛谷题目传送门 一道线性基的综合题 %%%%%% 首先注意到"非简单路径""异或和"等字眼,可以本能地想到线性基. ...

  3. 【bzoj3105】【cqoi2013】【新Nim游戏】【线性基+贪心】

    Description 传统的Nim游戏是这种:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量能够不同).两个游戏者轮流操作,每次能够选一个火柴堆拿走若干根火柴.能够仅仅拿一根,也能够拿走整堆火柴 ...

  4. 高斯消元 & 线性基【学习笔记】

    高斯消元 & 线性基 本来说不写了,但还是写点吧 [update 2017-02-18]现在发现真的有好多需要思考的地方,网上很多代码感觉都是错误的,虽然题目通过了 [update 2017- ...

  5. [HAOI2017]八纵八横 线性基

    题面 题面 题解 观察到题目中的 "内陆经济环" 不好处理,因此我们把它拆成 "内陆经济链". 对于1号节点,我们创建一个它的复制节点n + 1号节点,这个节点 ...

  6. P4570 [BJWC2011]元素 (线性基)

    题意:n个石头 每个石头有a,b两个属性 要求选出一些石头使得没有一个子集的a属性xor和为0 且b属性和最大 题解:线性基例题了.. 好像需要理解一些性质 1.原序列里任一数都可有由线性基xor得到 ...

  7. Codeforces 1100F(线性基+贪心)

    题目链接 题意 给定序列,$q(1\leq q \leq 100000) $次询问,每次查询给定区间内的最大异或子集. 思路 涉及到最大异或子集肯定从线性基角度入手.将询问按右端点排序后离线处理询问, ...

  8. CodeForces - 1100F:Ivan and Burgers (线性基&贪心)(离线 在线)

    题意:给定N个数,Q次询问,求区间最大异或和. 思路:一开始想的线性基+线段树.单次线性基合并的复杂度为20*20,结合线段树,复杂度为O(NlogN*20*20):显然,超时. 超时代码: #inc ...

  9. LOJ 6060「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set(线性基,贪心)

    LOJ 6060「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set $ solution: $ 这一题的重点在于优先级问题,我们应该先保证总和最大,然后再保证某一个最小.于是我 ...

随机推荐

  1. 浏览器端-W3School-JavaScript:Screen 对象

    ylbtech-浏览器端-W3School-JavaScript:Screen 对象 1.返回顶部 1. Screen 对象 Screen 对象 Screen 对象包含有关客户端显示屏幕的信息. 注释 ...

  2. UI自动化-selenium-api封装pyse框架

    # coding=utf-8 import time from selenium import webdriver from selenium.webdriver.common.action_chai ...

  3. 第 10 章 python进程与多进程

    一.背景知识 顾明思义,进程即正在执行的一个过程,进程是对正在云的程序的一个抽象. 进程的概念起源与操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一,操作系统的其他所 ...

  4. 用poi来导出数据到excel文档

    package cn.com.dyg.work.common.utils; import org.apache.poi.hssf.usermodel.HSSFRichTextString; impor ...

  5. SSM项目——乐淘商城话述1.0

    乐淘商城 项目介绍 淘淘网上商城是一个综合性的B2C平台,类似京东商城.天猫商城.会员可以在商城浏览商品.下订单,以及参加各种活动.管理员.运营可以在平台后台管理系统中管理商品.订单.会员等.客服可以 ...

  6. Pandas中关于 loc \ iloc 用法的理解

    转载至:https://blog.csdn.net/w_weiying/article/details/81411257 loc函数:通过行索引 "Index" 中的具体值来取行数 ...

  7. lua基础学习(六)

    一.lua协同程序coroutine 1.什么是协同(coroutine)?Lua 协同程序(coroutine)与线程比较类似:拥有独立的堆栈,独立的局部变量,独立的指令指针,同时又与其它协同程序共 ...

  8. mysql——单表查询——其它整理示例00

    ), sname ), sage ), ssex ) ); ','zhaolei','1990-01-01','nan'); ','qiandian','1990-12-21','nan'); ',' ...

  9. python 正则sub的使用

     self.content = re.sub(r'>|<',lambda x: '&gt' if x.group()[0] == '>' else '&lt' , s ...

  10. 在SQL Server 中创建外键

    建外键的前提是此外键必须是另外一个表的主键. 建外键的步骤: 第一步打开要建外键表的设计器,右击选择“关系”. 然后弹出“外键关系”窗体,我们选择“添加”,然后点击“表和列规范”后面的小按钮, 就会弹 ...