比赛
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
vector<int> a(6), b(6);
vector<int> sum_a(2), sum_b(2);
for (int i = 0; i < 6; ++i) {
cin >> a[i]; sum_a[i / 3] += a[i];
}
for (int i = 0; i < 6; ++i) {
cin >> b[i]; sum_b[i / 3] += b[i];
}
int res = 0;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
for (int k = 3; k < 6; ++k)
for (int m = 3; m < 6; ++m) {
int cnt = 0;
if (a[i] + a[k] < b[j] + b[m]) ++cnt;
if (sum_a[0] - a[i] < sum_b[0] - b[j]) ++cnt;
if (sum_a[1] - a[k] < sum_b[1] - b[m]) ++cnt;
if (cnt >= 2) ++res;
}
cout << res << "\n";
}
}
礼品
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int res = 0, N, P, S;
cin >> N;
unordered_set<int> st;
map<int, int> mp;
multiset<int> window;
auto mid = window.end();
for (int i = 0; i < N; ++i) {
cin >> P >> S;
if (i == 0) {
window.insert(S);
mid = window.begin();
++res;
st.insert(P);
}
else if (mp.count(P) && mp[P] >= S) continue;
else {
if (mp.count(P)) {
auto it = window.lower_bound(mp[P]);
if (it == mid) (window.size() % 2 == 1) ? ++mid : --mid;
else if (mp[P] <= *mid && window.size() % 2 == 1) ++mid;
else if (mp[P] > * mid && window.size() % 2 == 0) --mid;
window.erase(it);
}
window.insert(S);
if (S < *mid && window.size() % 2 == 1) --mid;
else if (S >= *mid && window.size() % 2 == 0) ++mid;
double t = (*mid + *prev(mid, 1 - window.size() % 2)) * 0.5;
if (t == S && !st.count(P)) {
++res;
st.insert(P);
}
}
mp[P] = S;
}
cout << res << "\n";
}
}
#笔试题目##网易#