P6346 [CCO2017] 专业网络 & CF1251E1 Voting(Easy Version)
analysis
这个题目我们可以考虑用贪心来做。
我们不难看出来,这个题目是要让我们推出这么个结论:花小钱,办大人。
整体贪心的思路就出来了,然后就是实现部分。
因为我们认识的人随便是谁都可以。所以我们如果要买肯定是买最便宜的。这个性质可以用小根堆来维护。同时我们还可以维护我们可能结交的人数 \(n - size_q\) 如果比这个人需要的人少直接白嫖不需要什么操作,如果不行就买下来这个人。
code time
原谅蒟蒻当时写的时候因为忘记怎么写小根堆了,所以多此一举写了个结构体。>_<
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rl register ll
#define x first
#define y second
typedef pair<ll, ll> pll;
const ll N = 2e5 +10;
ll n, ans;
pll a[N];
struct node
{
ll x;
bool operator <(const node &o) const
{
return x > o.x;
}
};
priority_queue<node> q;
int main()
{
// freopen("1.in", "r", stdin), freopen("1.out", "w", stdout);
scanf("%lld", &n);
for(rl i=0; i < n; ++ i) scanf("%lld%lld", &a[i].x, &a[i].y);
sort(a, a + n);
for(rl i=n - 1; i >= 0; -- i)
{
q.push({a[i].y});
if(a[i].x > n - q.size())
{
auto t = q.top();
ans += t.x;
q.pop();
}
}
printf("%lld", ans);
return 0;
}
P6346 [CCO2017] 专业网络 & CF1251E1 Voting(Easy Version)的更多相关文章
- Ping-Pong (Easy Version)(DFS)
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ZOJ 3868 - Earthstone: Easy Version
3868 - Earthstone: Easy Version Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld ...
- Codeforces 1077F1 Pictures with Kittens (easy version)(DP)
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...
- UVA12569-Planning mobile robot on Tree (EASY Version)(BFS+状态压缩)
Problem UVA12569-Planning mobile robot on Tree (EASY Version) Accept:138 Submit:686 Time Limit: 300 ...
- Coffee and Coursework (Easy version)
Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabyte ...
- 2016级算法第六次上机-B.ModricWang's FFT : EASY VERSION
1114 ModricWang's FFT EASY VERSION 思路 利用FFT做大整数乘法,实际上是把大整数变成多项式,然后做多项式乘法. 例如,对于\(1234\),改写成\(f(x)=1* ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...
- Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...
- Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...
随机推荐
- 如何构建您的第一部AWS机器学习服务
目录 <如何构建您的第一部 AWS 机器学习服务> 背景介绍 随着深度学习的广泛应用于机器学习领域的各个方面,AWS 成为了一种重要的深度学习平台.作为 AWS 机器学习服务的第一部,如何 ...
- Mybatis-plus自定义Sql注入器
最近在学习mybatis-plus,知道了在mp中通过AbstractSqlInjector将BaseMapper中的方法注入到了Mybatis容器,这样这些方法才可以正常执行. 下面是一个关系图 那 ...
- Educational Codeforces Round 151 (Rated for Div. 2) A-D
A 代码 #include <bits/stdc++.h> using namespace std; using ll = long long; bool solve() { int n, ...
- 如何给Github上的开源项目提交PR?
前言 对于一个热爱开源的程序员而言,学会给GitHub上的开源项目提交PR这是迈出开源的第一步.今天我们就来说说如何向GitHub的开源项目提交PR,当然你提交的PR可以是一个项目的需求迭代.也可以是 ...
- 项目完成小结:使用Blazor和gRPC开发大模型客户端
前言 先介绍下这个项目. 最近我一直在探索大语言模型,根据不同场景训练了好几个模型,为了让用户测试使用,需要开发前端. 这时候,用 Gradio 搭建的前端是不太够的,虽说 GitHub 上也有一堆开 ...
- 基于LLVM的海量数据排序算法研究。(二维表的排序算法)
当待排序数据内容大于内存容量时,需将待排序内容分块,要进行排序的分块传入内存,未处于排序状态的存入外存,外存的读写时间是内存的百万倍,因此在内外存储器之间传输分块所消耗的 I/O 时间是大数据排序算法 ...
- Linux 概念:grub2
GRUB 2是许多发行版的缺省efi模式引导加载程序. grub2 与 grub 的区别 官方手册:https://www.gnu.org/software/grub/manual/grub/html ...
- Redis从入门到放弃(2):数据类型
在Redis中,数据以键值对的形式存储.Redis支持五种主要的数据类型,每种类型都有不同的用途和特性. 本文将介绍Redis的五种数据类型:字符串(string),哈希(hash),列表(list) ...
- django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported.
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing a ...
- Cilium系列-9-主机路由切换为基于 BPF 的模式
系列文章 Cilium 系列文章 前言 将 Kubernetes 的 CNI 从其他组件切换为 Cilium, 已经可以有效地提升网络的性能. 但是通过对 Cilium 不同模式的切换/功能的启用, ...