TuringPuth @ 2024-07-22 15:28:01
样例都没问题!!!但是全WA了!!!求助!!
#include <bits/stdc++.h>
using namespace std;
int n,a,ans,x,y;
priority_queue<int>q;//tiny
priority_queue<int,vector<int>,greater<int> >p;//large
int main(){
scanf("%d%d",&n,&a);
ans=a;
printf("%d\n",ans);
for(int i=1;i<=n/2;i++){
scanf("%d%d",&x,&y);
if(x>y) swap(x,y);
if(x<ans&&y<ans){
p.push(ans);
q.push(x);
q.push(y);
ans=q.top();
q.pop();
}
else if(x>ans&&y>ans){
q.push(ans);
p.push(x);
p.push(y);
ans=p.top();
p.pop();
}
else{
q.push(x);
p.push(y);
}
printf("%d\n",ans);
}
return 0;
}
这个做题思路有问题吗? 就是分两个堆
by Billy_Zhang @ 2024-07-25 15:52:21
没有,老师是这么讲的。但我也没对
by WWJ114514 @ 2024-07-27 10:33:56
@TuringPuth
输入:
100
952648061 811707742 126499815 513645053 866027642 926654980 291860010 771852889 370773340 989042449 108194835 667310184 126205281 625961478 947202409 513555136 889120678 149674727 607940261 106258581 162767446 330514850 589282336 436752728 140142180 438410867 620329591 982958302 416347357 436148635 333352825 120925277 604956742 864207662 51557114 122423619 460017788 327049561 700166875 841616086 92289691 481701355 98519879 656618860 228928121 31953087 299224162 551766871 152547131 806454996 656957222 120283760 860209326 54275255 853532685 746374636 751870794 768767253 900554494 431342600 59963261 465634686 960298139 493358672 827420012 249619893 351571976 232207383 495832349 696350241 480746667 449791377 778395756 91817705 127786354 946839468 618264165 219287600 821906384 967939445 953899369 829452875 694795990 752650829 206692561 206250575 605154961 937565791 590990740 211329272 196540344 486024277 705363202 942704474 106097705 293476862 882327079 404331569 636749672 495948134
输出:
952648061 811707742 811707742 811707742 771852889 771852889 667310184 667310184 667310184 625961478 607940261 589282336 513645053 513645053 513645053 513555136 513555136 513555136 460017788 460017788 460017788 460017788 460017788 438410867 438410867 460017788 460017788 460017788 481701355 513555136 481701355 481701355 493358672 481701355 481701355 481701355 481701355 480746667 481701355 481701355 493358672 495832349 495832349 495832349 513555136 495832349 495832349 495832349 495832349 495832349
by TuringPuth @ 2024-07-28 21:21:33
@WWJ114514 虽然谢谢大佬但是 我还是不会呀啊啊啊呜呜呜呃呃呃嘤嘤嘤求调[膜拜]
by WWJ114514 @ 2024-07-28 21:26:48
@TuringPuth 应该是奇数偶数的问题,你只考虑了奇数
by TuringPuth @ 2024-07-28 21:58:58
@WWJ114514 谢谢大佬 我调下
by WWJ114514 @ 2024-07-28 22:05:47
@TuringPuth 虽然我也没过