今天晚上参加比赛的人真少,这怕不是又要掉分。
D. Even-Odd Game
题意:A先挑选数字,如果为偶数,则加到A,为奇数则不变,B接着挑数字,如果为偶数,值不变,为奇数,则加到B。A,B都采取最优的方法,你需要判断谁最后能赢。
我们知道,如果A挑了偶数,则其加上,挑奇数,可变向的认为B无法再选这个奇数,为了使自己的值最大,B的值最小,每次都要挑选最大的数,B同理。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
int a[N];
int t, n;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
cin >> t;
while (t -- )
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n, cmp);
ll ansa = 0, ansb = 0;
for (int i = 1; i <= n; i ++ )
{
if (i % 2 == 1)
{
if (a[i] % 2 == 1) ansa += 0;
else ansa += a[i];
}
else
{
if (a[i] % 2 == 1) ansb += a[i];
else ansb += 0;
}
}
if (ansa == ansb) cout << "Tie" << endl;
else if (ansa > ansb) cout << "Alice" << endl;
else cout << "Bob" << endl;
}
return 0;
}
C. Berpizza
题意:M服务最早来饭店的顾客。P服务能付出的钱最多的顾客,如果付出前相同,则服务来的时间早的人。每次服务后,都将被服务的人的序号输出来,序号按照顾客来到饭店的时间顺序从1开始排。
学到了集合的重载运算符。
之前学的优先队列的重载运算符
struct cmp{
bool operator () (const node &a, const node &b) const {
if (a.prior == b.prior)
return a.id > b.id;
return a.prior < b.prior;
}
};
priority_queue <node, vector<node>, cmp> doc[4];
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 500050;
struct cmp
{
bool operator () (const PII &a, const PII &b) const
{
if (a.first != b.first) return a.first > b.first;
return a.second < b.second;
}
};
set<PII, cmp> q1;
set<int> q2;
int cnt[N];
int q;
int op, x;
int main()
{
cin >> q;
int idx = 0;
while (q -- )
{
cin >> op;
if (op == 1)
{
cin >> x;
cnt[ ++ idx] = x;
q1.insert({x, idx});
q2.insert(idx);
}
else if (op == 2)
{
int cur = *q2.begin();
q2.erase(cur);
q1.erase({cnt[cur], cur});
cout << cur << ' ';
}
else
{
PII tmp = *q1.begin();
int cur = tmp.second;
q1.erase(tmp);
q2.erase(cur);
cout << cur << ' ';
}
}
return 0;
}