求助QAQ

P1168 中位数

abs那里错惹
by 羽儇 @ 2019-10-03 20:44:51


@[Bilion_冰凌帅](/space/show?uid=54372) abs里面+1什麽鬼
by 羽儇 @ 2019-10-03 20:47:46


@[羽儇](/space/show?uid=116162) 好像没什么问题啊XD 而且改成这样: int abs(int x) {return x>=0?x:-x;} 还是WA啊XDD
by A_Đark_Horcrux @ 2019-10-03 20:51:03


@[Bilion_冰凌帅](/space/show?uid=54372) 令人眼花缭乱的双目运算符 记住, a.size()>b.size()?~~b.push(a.top()),a.pop(~~):~~a.push(b.top()),b.pop()~~; 是错误的写法,用双目写时,不能加逗号 ```cpp #include<cstdio> #include<queue> using namespace std; priority_queue<int,vector<int> > a; priority_queue<int,vector<int>,greater<int> > b; int abs(int x) {return x>=0?x:-x;} int n,x,i; int main() { scanf("%d %d",&n,&x); a.push(x); printf("%d\n",a.top()); for(i=2;i<=n;i++) { scanf("%d",&x); x>a.top()?b.push(x):a.push(x); while(abs(int(a.size())-int(b.size()))>1) { if(a.size()>b.size())b.push(a.top()),a.pop(); else a.push(b.top()),b.pop(); } if(i%2) printf("%d\n",a.size()>b.size()?a.top():b.top()); } return 0; } ```
by 羽儇 @ 2019-10-03 21:06:59


改成这样就AC惹qwq
by 羽儇 @ 2019-10-03 21:07:19


|