题目:题目链接

题意:给出n种食物,食物有自己的价格并且可以自由搭配,每天吃之前没吃过的花费最少的搭配,问第k天的花费。

思路:第k小我们考虑用优先队列处理,虽然n比较大,但由于1 ≤ K ≤ min(106, 2N - 1),只要我们控制好每次往队列里压的的元素个数,问题是可以解决的,控制方法见代码。

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <stack> #define FRER() freopen("in.txt", "r", stdin)
#define FREW() freopen("out.txt", "w", stdout)
#define INF 0x3f3f3f3f using namespace std; const int maxn = 2e5 + ;
int n, k; long long num[maxn]; typedef pair<long long, int> P; int main()
{
ios::sync_with_stdio();
cin.tie(); cin >> n >> k;
for(int i = ; i < n; ++i)
cin >> num[i];
sort(num, num + n); priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(num[], ));
P tmp;
for(int i = ; !q.empty() && i < k; ++i) {
tmp = q.top();
q.pop(); if(tmp.second < n - ) {
q.push(make_pair(tmp.first + num[tmp.second + ], tmp.second + ));
q.push(make_pair(tmp.first - num[tmp.second] + num[tmp.second + ], tmp.second + ));
}
} cout << q.top().first << endl;
return ;
}

G - Dreamoon and NightMarket Gym - 101234G 优先队列+思路的更多相关文章

  1. Codeforces Gym101234G Dreamoon and NightMarket(优先队列,子集和第k大)

    题意: 求子集和第k大,n,k<=1e6 思路: 优先队列经典题目,注意优先队列是默认按从大到小排的 代码: #include<iostream> #include<cstdi ...

  2. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  3. 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列

    Problem G: Array C Time Limit: 1 Sec  Memory Limit: 128 MB Description Giving two integers  and  and ...

  4. 2016 百度之星初赛 Gym Class(优先队列+拓扑排序)

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

  5. 中矿大新生赛 G 甄总搬石头【优先队列/哈夫曼/贪心】

    时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 https://www.nowcoder.com/ ...

  6. G - 土耳其冰淇凌 Gym - 101194D(二分答案 + 贪心检验)

    熊猫先生非常喜欢冰淇淋,尤其是冰淇淋塔.一个冰淇淋塔由K个冰淇淋球堆叠成一个塔.为了使塔稳定,下面的冰淇淋球至少要有它上面的两倍大.换句话说,如果冰淇淋球从上到下的尺寸是A0, A1, A2,···, ...

  7. Two Operations Gym - 102263M 优先队列水题

    Two Operations Gym - 102263M Ayoub has a string SS consists of only lower case Latin letters, and he ...

  8. Codeforces Round #570 (Div. 3) G. Candy Box (hard version) (贪心,优先队列)

    题意:你有\(n\)个礼物,礼物有自己的种类,你想将它们按种类打包送人,但是打包的礼物数量必须不同(数量,与种类无关),同时,有些礼物你想自己留着,\(0\)表示你不想送人,问你在送出的礼物数量最大的 ...

  9. G - Rescue 【地图型BFS+优先队列(有障碍物)】

    Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...

随机推荐

  1. Mincost

    The cost of taking a taxi in Hangzhou is not a constant for each kilometer you travel: the first 4 k ...

  2. Day1 了解web前端

    Day1  了解web前端 一.职业发展路线: 前端页面制作.前端开发.前端架构师 二.1)前端工程师主要职责:   利用HTML/CSS/JavaScript等各种Web技术进行客户端产品的开发.完 ...

  3. 微信小程序实战篇:基于wxcharts.js绘制移动报表

    前言 微信小程序图表插件(wx-charts)是基于canvas绘制,体积小巧,支持图表类型饼图.线图.柱状图 .区域图等图表图形绘制,目前wx-charts是微信小程序图表插件中比较强大好使的一个. ...

  4. If you want the rainbow, you have to deal with the rain.

    If you want the rainbow, you have to deal with the rain.想要彩虹,就先忍受雨水.

  5. ssh-agent && ssh-agent forward && SSH ProxyCommand

    http://blog.csdn.net/sdcxyz/article/details/41487897 https://developer.github.com/guides/using-ssh-a ...

  6. js01

    /////////////////////////////////////////////////////////////js开端/////////////////////////////////// ...

  7. Seafile开源私有云自定义首页Logo图片

    Seafile是一个开源.专业.可靠的云存储平台:解决文件集中存储.共享和跨平台访问等问题,由北京海文互知网络有限公司开发,发布于2012年10月:除了一般网盘所提供的云存储以及共享功能外,Seafi ...

  8. node实现爬虫

    node实现获取到豆瓣电影排行榜页面. 准备工作: 1.新建一个文件夹node 在当前文件夹中打开cmd 下载 npm install 初始化 npm init(注意一下:如果你的npm init没有 ...

  9. 我的Java修养

    无论如何我都会以这种方式严于律己,如有错误接受修正. 1.戒掉对友情和爱情的幻想 2.针对人的行为进行分析,而不是其语言 3.解决一个问题,这个问题会成为解决后续问题的基础和前提 4.不要炫耀,自负, ...

  10. Poj(2560),最小生成树,Prim

    题目链接:http://poj.org/problem?id=2560 只想说“全都是套路”,关键建图. #include <stdio.h> #include <string.h& ...