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 ...
随机推荐
- vue前端预览pdf并加水印、ofd文件,控制打印、下载、另存,vue-pdf的使用方法以及在开发中所踩过的坑合集
根据公司的实际项目需求,要求实现对pdf和ofd文件的预览,并且需要限制用户是否可以下载.打印.另存pdf.ofd文件,如果该用户可以打印.下载需要控制每个用户的下载次数以及可打印的次数.正常的预览p ...
- docker-compose多服务器部署ELK
多服务器构建ELK es使用1主2从,logstash转发,kibana展现,本文ELK版本使用7.16.1 如果单机测试,请查看docker-compose单服务器部署ELK es-master:1 ...
- 前端Vue加载中页面动画弹跳动画loading
前端Vue加载中页面动画弹跳动画loading, 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13091 效果图如下: 使用方法 ...
- uniapp学习(二)
easycom自动导入自定义组件 目录下 components / MyItem /MyItem.vue <template> <view> <view class=&q ...
- Python 逻辑表达式的妙用
今天偶然看到有这样一段代码,感到很惊讶: super().__init__(package_name or (robot_name + "_moveit_config")) 语义非 ...
- CF1799B Equalize by Divide题解
本蒟蒻学习了jiangly大佬的思想,来发一个题解. 大致题意: 给定一个 \(n\) 个元素的数组 \(a\),每次可以选择 \(a[i]\) 和 \(a[j]\),然后使 \(a[i] = \lc ...
- Unity UGUI的CanvasScaler(画布缩放器)组件的介绍及使用
Unity UGUI的CanvasScaler(画布缩放器)组件的介绍及使用 1. 什么是CanvasScaler组件? CanvasScaler是Unity中UGUI系统中的一个组件,用于控制画布的 ...
- CSP-S复习列表
DP:序列,区间,背包,多维,状压,树型 优化:滚动,单调性,树状数组 数据结构:栈,队,链,deque,priority_queue,vector,set,map 树状数组,分块思想 前缀和,差分思 ...
- vulnhub billu:b0x
知识点 SQLi.目录爆破.数据库操作.文件包含漏洞.提权.反弹shell 解题步骤 nmap扫描有80,22端口 nmap -sV -Pn -T 4 192.168.220.132 访问网页提示sq ...
- cesium中限制地图浏览范围
https://blog.csdn.net/qq_42740164/article/details/119375782?ops_request_misc=%257B%2522request%255Fi ...