社区讨论
全wa???
P3378【模板】堆参与者 8已保存回复 12
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 12 条
- 当前快照
- 1 份
- 快照标识符
- @mi6yvsjv
- 此快照首次捕获于
- 2025/11/20 13:04 4 个月前
- 此快照最后确认于
- 2025/11/20 15:38 4 个月前
手写小根堆怎么全wale ??
求dalao看一下```cpp
#include
using namespace std;
int heap[1000007];
int n;
int heap_size;
void swap(int a,int b)
{
int tmp;
tmp=a;
a=b;
b=tmp;
}
void add(int a)
{
heap[++heap_size]=a;
int now=heap_size,next;
CPPwhile(now>1)
{
next=now>>1;
if(heap[now]>=heap[next]) return;
swap(heap[now],heap[next]);
now=next;
}
}
void del()
{
int now=1,next;
heap[1]=heap[heap_size--];
while(now2<=heap_size)
{
next=now2;
if(next<heap_size&&heap[next+1]<heap[next]) next++;
if(heap[next]>=heap[now]) break;
swap(heap[next],heap[now]);
now=next;
}
}
int main()
{
int x;
cin>>n;
//heap_size=n;
int num;
for(int i=1;i<=n;i++)
{
cin>>x;
if(x==1)
{
cin>>num;
add(num);
}
CPP if(x==2)
{
cout<<heap[1]<<endl;
}
if(x==3)
{
del();
}
}
return 0;
}
CPP回复
共 12 条回复,欢迎继续交流。
正在加载回复...