AcWing 3539. 复数集合
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N];
string str;
struct mcomplex {
int a, b;
mcomplex(int aa, int bb): a(aa), b(bb) {};
bool operator<(const mcomplex&mc)const {
double ma = sqrt(a * a + b * b);
double mb = sqrt(mc.a * mc.a + mc.b * mc.b);
if (ma == mb)return b > mc.b;
return ma < mb;
}
void print() {
printf("%d", a);
if (b >= 0)printf("+i");
printf("%d\n", b);
}
};
void solve() {
cin >> n;
priority_queue<mcomplex> pq;
for (int i = 1; i <= n; i++) {
cin >> str;
if (str == "Pop") {
if (pq.empty()) {
printf("empty\n");
} else {
mcomplex mc = pq.top();
mc.print();
pq.pop();
printf("SIZE = %d\n", (int)pq.size());
}
} else if (str == "Insert") {
scanf("%d+i%d", &x, &y);
pq.push(mcomplex(x, y));
printf("SIZE = %d\n", (int)pq.size());
}
}
}
int main() {
solve();
return 0;
}