首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
carrot_huan
2024年3月18日 10:37
合并果子 题解:优先级队列
P1544
回复 0
|
赞 0
|
浏览 1.1k
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; priority_queue<int ,vector<int>,greater<int>>data; int t; for (int i = 0; i < n;...
xjnotywlq
2024年3月9日 15:22
合并果子 题解:为啥还是超时了
P1544
回复 2
|
赞 9
|
浏览 1.1k
#include <stdio.h> #include <stdlib.h> int cmp(const void *a,const void*b){ return *(int*)b-*(int*)a; } int main() { int n; scanf("%d",&n); int res[1000]; for(int i=0;i<n;i++)scanf...
孙某人
2024年2月17日 10:45
合并果子 题解:新手易错
P1544
回复 0
|
赞 2
|
浏览 1.2k
#include <iostream> #include <string.h> using namespace std; int main(){ int n; cin >>n; long long int a[10005],b[10005],min=0,minn=0,sum=0; int mini=0,minni=0,cc; for(int i=0;i<10005;i++){ a[i]=0; b[i]=0; } for(int i=0;i<n;i++) cin >> a...
DestinyCares+++
2024年1月29日 18:36
合并果子 题解:
P1544
回复 0
|
赞 1
|
浏览 1.2k
#include<bits/stdc++.h> using namespace std; int main(){ priority_queue<int,vector<int>,greater<int>> que; int n,sum,temp=0,weight=0; cin>>n; for(int i=1;i<=n;i++){ &...
小李122333
2024年1月18日 23:16
合并果子 题解:优先队列
P1544
回复 0
|
赞 1
|
浏览 1.3k
#include <bits/stdc++.h> using namespace std; struct node{ int x; node(int a){ x=a; } }; bool operator<(const node &a,const node&b){ return a.x>b.x; } int main(){ priority_queue<node> q; int n,x; cin>>n; for(int i=0;i<n;i++){ cin>...
xx_about123456
2022年8月6日 14:58
利用优先队列解决哈夫曼树题目
P1544
回复 0
|
赞 7
|
浏览 6.0k
总体思路: 对于给出的一系列结点,先将权值更小的两个结点合并,并将新结点加入原系列,直到原系列只剩下一个结点 实现方法: 利用优先队列(升序),取队首和次对首合并,加入队列,直到队列只有一个元素。 带注释代码 #include<bits/stdc++.h> using namespace std; int main() { int num; cin>>num; priority_queue<int,vector<int>,greater<int>> q...
tuesdasy
2022年3月7日 11:13
优先队列合并果子
P1544
回复 0
|
赞 1
|
浏览 5.2k
新手 #include <iostream> using namespace std; #include <queue> #include <vector> int main () { int n, sum = 0, sum2 = 0; scanf ("%d", &n); priority_queue<int, vector<int>, greater<int> > q;//小根堆,升序排列 for (int i = 0; i < n; i++) { ...
James
2021年1月31日 18:35
优先队列priority_queue模拟堆
P1544
回复 0
|
赞 0
|
浏览 8.2k
#include <iostream> #include <stack> #include <queue> using namespace std; struct node{ int x; }; priority_queue<node> q; bool operator<(node a,node b){ return a.x>b.x; } int main(){ int n; &...
wudiyiyi
2020年4月16日 08:12
用优先队列(小根堆),每次选择最小的两堆合成一堆再放入队列中
P1544
回复 0
|
赞 1
|
浏览 11.4k
#include <bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,greater<int> >q;///小根堆,权值小的先出队 int main() { int n,v,ans=0; scanf("%d",&n); while(n--) { scanf("%d",&v); q.push(v); } while(q.size()>...
mzymzyo
2020年3月23日 00:06
题解:合并果子
P1544
回复 0
|
赞 0
|
浏览 11.1k
题目很容易看出贪心策略:每次只合并最小的两堆 但是每次合并后的堆还要放回去,得保证放回去后数据依旧有序 这里介绍一种数据结构:优先队列,头文件#include <queue> 这个队列弹出元素不是按照入队的先后,而是按照权值的大小出队。 定义: priority_queue<int> q; 定义队列q,权值大的先出队 priority_queue <int, vector<int>, greater<int> > q;权值小的先出队 #include<bi...
1
2
题目
合并果子
题解数量
20
发布题解
在线答疑
热门题解
1
合并果子 题解:
2
合并果子 题解:c++ priority_queue<int> 实现
3
合并果子 题解:果宝机甲,归位!
4
合并果子 题解:优先队列
5
合并果子 题解:为啥还是超时了
6
利用优先队列解决哈夫曼树题目
7
合并果子 题解:优先队列
8
合并果子(C)
9
合并果子 题解:暴力
10
合并果子 题解:链表解法