神奇的错误

P1168 中位数

@[Robinzh](/space/show?uid=53807) ```cpp #include <iostream> #include <vector> #include <queue> using namespace std; int n,a; priority_queue< int , vector<int> , greater<int> >q1;//递增 priority_queue< int ,vector<int> >q2; //递减 int main() { cin>>n;cin>>a; q2.push(a); cout<<q2.top()<<endl; for(int z=2;z<=n;z++) { cin>>a; if(a<=q2.top()) q2.push(a); else q1.push(a); if(q1.size()-q2.size()>1) {q2.push(q1.top());q1.pop();} if(q1.size()+1<q2.size()) {q1.push(q2.top());q2.pop();} if((z+1)%2==0) { if(q2.size()>q1.size())cout<<q2.top()<<endl; if(q2.size()<q1.size()) cout<<q1.top()<<endl; } } return 0; } ```
by NieR_Automata @ 2018-10-23 21:32:03


下个数据跑一下不就知道了?
by Southern_way @ 2018-10-23 21:33:44


@[雄英天下第一](/space/show?uid=94365) ~~我多了几次判断~~(逃
by NieR_Automata @ 2018-10-23 21:35:21


@[NieR_Automata](/space/show?uid=105333) emmmm,不应该用while循环来维护吗(逃
by Southern_way @ 2018-10-23 21:36:26


@[雄英天下第一](/space/show?uid=94365) 程序会停止工作
by NieR_Automata @ 2018-10-23 21:38:42


@[雄英天下第一](/space/show?uid=94365) ~~好像每次差的不会过2~~(逃
by NieR_Automata @ 2018-10-23 21:41:53


可能因为size()函数的某些奇怪性质吧(逃
by Southern_way @ 2018-10-23 21:43:03


@[NieR_Automata](/space/show?uid=105333) size()好像是STL的属性,直接拿来减可能会RE吧(逃
by Southern_way @ 2018-10-23 21:44:57


@[雄英天下第一](/space/show?uid=94365) 看来只能这么解释了
by NieR_Automata @ 2018-10-23 21:47:48


@[雄英天下第一](/space/show?uid=94365) daolao告诉我说 .size()的返回值是unsigned
by NieR_Automata @ 2018-10-23 21:54:14


上一页 | 下一页