文章

166

粉丝

68

获赞

855

访问

61.7k

头像
复数集合 题解:priority_queue
P1381 北京邮电大学机试题
发布于2025年2月11日 13:15
阅读数 301

#include <bits/stdc++.h>

using namespace std;

struct pl {
    int a, b;
    pl(int a, int b): a(a), b(b) {}
    bool operator < (pl y) const {
        return a * a + b * b < y.a * y.a + y.b * y.b;
    }
};

int main() {
    int n;
    while (cin >> n) {
        priority_queue<pl> pq;
        while (n--) {
            string s;
            cin >> s;
            if (s == "Pop") {
                if (pq.empty()) {
                    cout << "empty" << endl;
                } else {
                    int a=pq.top().a,b=pq.top().b;
                    cout<<a<<"+i"<<b<<endl;
                    pq.pop();
                    cout << "SIZE = " << pq.size() << endl;
                }
            } else {
                int a, b;
                char plus, i;
                cin >> a >> plus >> i >> b;
                if (plus == '+' && i...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发