C++-hihoCode-1105/1109-[STL][堆][prime]
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=;
priority_queue<int>q;
int m,a;string s;
int main(){
for(cin>>m;m--;){
cin>>s;
if(s=="A")cin>>a,q.push(a);
else {
cout<<q.top()<<endl;
q.pop();
}
}
return ;
}
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=1e5+;
priority_queue<pair<int,int> >q;
vector<pair<int,int> >E[MAXN];
int n,m,u,v,w,ans,vis[MAXN];
pair<int,int>e;
void update(int u){
vis[u]=true;
for(int i=;i<E[u].size();i++)
if(!vis[E[u][i].second])q.push(E[u][i]);
}
int main(){
for(cin>>n>>m;m--;){
cin>>u>>v>>w;
E[u].push_back(make_pair(-w,v));
E[v].push_back(make_pair(-w,u));
}
update();//以下为prime最小生成树(小根堆优化)算法
for(int i=;i<n;i++)
while(!q.empty()){
e=q.top(),q.pop(),v=e.second;
if(vis[v])continue;
ans+=-e.first,update(v);
break;
}
cout<<ans<<endl;
return ;
}
C++-hihoCode-1105/1109-[STL][堆][prime]的更多相关文章
- BZOJ 1109: [POI2007]堆积木Klo
1109: [POI2007]堆积木Klo Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 948 Solved: 341[Submit][Statu ...
- C++ STL堆操作
/* STL 最大堆.最小堆的应用 */ #include <iostream> #include <vector> #include <algorithm> // ...
- 1109: [POI2007]堆积木Klo
1109: [POI2007]堆积木Klo https://lydsy.com/JudgeOnline/problem.php?id=1109 分析: 首先是dp,f[i]表示到第i个的最优值,f[i ...
- STL 堆
洛谷P3378 [模板]堆 #include <iostream> #include <cstdio> #include <algorithm> #include ...
- STL 堆的使用
本来是要写leetcode上的merge k sorted lists那道题目,这个题目我还是很熟悉的,毕竟是看过算法导论的人,但是写的过程中对堆的维护代码还是挺多的,所以我想到了STL中的堆.下面就 ...
- 堆以及stl堆的使用
概念 性质: 1.堆是一颗完全二叉树,用数组实现. 2.堆中存储数据的数据是局部有序的. 最大堆:1.任意一个结点存储的值都大于或等于其任意一个子结点中存储的值. 2.根结点存储着该树 ...
- BZOJ 1109 [POI2007]堆积木Klo(树状数组)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1109 [题目大意] Mary在她的生日礼物中有一些积木.那些积木都是相同大小的立方体. ...
- bzoj1293: [SCOI2009]生日礼物(stl堆)
1293: [SCOI2009]生日礼物 题目:传送门 题解: 据说这道题乱搞随便就水过了 本蒟蒻想到了一个用堆的水法(还专门学了学queue): 如果把每一种颜色的下一个位置都记录一下的话,一开始就 ...
- 【BZOJ】1109: [POI2007]堆积木Klo
题意 \(n(1 \le n \le 100000)\)个数放在一排,可以一走一些数(后面的数向前移),要求最大化\(a_i=i\)的数目. 分析 分析容易得到一个dp方程. 题解 \(d(i)\)表 ...
随机推荐
- React.js高阶函数的定义与使用
/* 高阶函数的简单定义与使用 一: 先定义一个普通组件 二: 用function higherOrder(WrappendComponent) { return } 将组件包裹起来,并用export ...
- nginx模块之ngx_http_upstream_module
ngx_http_upstream_module 示例: http上下文: upstream upservers{ ip_hash; //根据客户端IP进行调度,每个客户端ip地址访问时每个ip生成一 ...
- 纪中集训2020.02.05【NOIP提高组】模拟B 组总结反思——【佛山市选2010】组合数计算,生成字符串 PPMM
目录 JZOJ2290. [佛山市选2010]组合数计算 比赛时 之后 JZOJ2291. [佛山市选2010]生成字符串 比赛时 之后 JZOJ2292. PPMM 比赛时 之后 JZOJ2290. ...
- [PAT] A1017 Queueing at Bank
[思路] 1:将所有满足条件的(到来时间点在17点之前的)客户放入结构体中,结构体的长度就是需要服务的客户的个数.结构体按照到达时间排序. 2:wend数组表示某个窗口的结束时间,一开始所有窗口的值都 ...
- BugkuCTF flag.php(反序列化)
进去后是个登录页面,但是login根本不会跳转,看源码也没提示,但是这道题给了一个提示:hint,那么盲猜应该是一个get参数,因为post不能跳转,那么get总有内容吧,跟上hint参数,随便赋一个 ...
- python3练习100题——054
题目:取一个整数a从右端开始的4〜7位. a=input('please input a num:') print(a[-7:-3])
- virtual box虚拟机跨物理机迁移
VirtualBox保存虚机数据的是vdi文件,但是直接拷贝在新的VirtualBox中不能打开,因为每个vdi文件都包含了一个uuid的数据,如果直接拷贝,uuid在新的VirtualBox中是不能 ...
- nodeJS菜鸟教程笔记
http模块 var http = require('http'); // 引入http模块 var url = require('url'); // 引入url模块 var querystring ...
- JavaSE学习笔记(1)---数据类型、运算符、控制结构
javaSE学习笔记(1) 数据类型和运算符 1.注释可以提高程序的可读性.可划分为 单行注释 // 多行注释 /.../ 文档注释 /**...*/ 2.标识符的命名规则: 标识符必须以字母.下划线 ...
- 假期学习【四】RDD编程实验一
1.今天把Spark编程第三个实验的Scala独立程序编程写完了.使用 sbt 打包 Scala 程序,然后提交到Spark运行. 2.完成了实验四的第一项 (1)该系总共有多少学生: map(t ...