CE蒟蒻求助

P1168 中位数

tocek_shiki @ 2018-10-15 21:08:20

测评记录:QwQ

#include <bits/stdc++.h>
#define newline printf ("\n")
#define space printf (" ")
#define cinfalse ios::sync_with_stdio(false)
#define fread(a) freopen (a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rint register int
#define For(i, a, b) for (rint i = a; i <= b; i ++)
#define Low(i, a, b) for (rint i = a; i >= b; i --)
#define FFr(i, a, b, c) for (rint i = a; i <= b; i += c)
#define FLw(i, a, b, c) for (rint i = a; i >= b; i -= c)
#define min(a, b) (a)>(b)?(b):(a)
#define max(a, b) (a)>(b)?(a):(b)
using namespace std;

priority_queue < int > q1;
priority_queue < int, vector < int >, greater < int > > q2;
int n; 
int abs (int x)
{
    return x<0?-x:x;
 } 
int main()
{
    scanf ("%d", &n);
    rint tmplate;
    scanf ("%d", &tmplate);
    q1.push(tmplate);
    printf ("%d\n", tmplate);
    For (i, 2, n)
    {
        scanf ("%d", &tmplate);
        if (tmplate > q1.top()) q2.push(tmplate);
        else q1.push(tmplate);
        while (abs (q1.size()-q2.size()) > 1)
            if (q1.size() > q2.size()) q2.push(q1.top()), q1.pop();
            else q1.push(q2.top()), q2.pop();
        if (i%2) printf ("%d\n", q1.size()>q2.size()?q1.top(): q2.top());
    }
    return 0;
}

by touristX @ 2018-10-15 21:11:28

@fff团666 abs函数换个名字吧。。有用。。


by fbhou @ 2018-10-15 21:12:14

@fff团666 开了-Wall 开了-pedantic 开了-Werror 只找到一个tmplate不能register


by fbhou @ 2018-10-15 21:13:04

改了就没了(


by tocek_shiki @ 2018-10-15 21:17:08

@touristX 是的,是这个的锅,已A

@fbhou tmplate是没错的,我特意没打e,防止``` template


重名

by tocek_shiki @ 2018-10-15 21:17:49

此贴已终结,谢谢各位


|