Untitled
unknown
plain_text
a year ago
2.7 kB
9
Indexable
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
struct res {
int mCost, mContent;
};
struct Mineral {
int cost, mineID, content;
};
struct comp {
bool operator()(Mineral m1, Mineral m2) const {
return m1.cost < m2.cost;
}
};
set<Mineral, comp> mine_comb[2][3];
int shipfee;
void init(int mShipFee) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++)
mine_comb[i][j].clear();
}
shipfee = mShipFee;
}
int gather(int mMineId, int mType, int mCost, int mContent) {
Mineral mid;
mid.content = mContent; mid.cost = mCost; mid.mineID = mMineId;
mine_comb[mMineId][mType].insert(mid);
mine_comb[2][mType].insert(mid);
return mine_comb[mMineId][mType].size();
}
res mix(int mBudget) {
int row = -1;
res res;
res.mContent = 0; res.mCost = 0;
int price = 0;
int content = -1;
Mineral del[3];
for (int i = 0; i < 3; i++) {
auto m = mine_comb[i][0].begin();
auto m1 = mine_comb[i][1].begin();
auto m2 = mine_comb[i][2].begin();
while (m != mine_comb[i][0].end() && m1 != mine_comb[i][1].end() && m2 != mine_comb[i][2].end())
{
int p = m->cost + m1->cost + m2->cost + shipfee;
if (i == 2)p += shipfee;
if (p <= mBudget) {
int c = min({ m->content,m1->content,m2->content });
if (c > content || (c == content && p < price)) {
content = c;
price = p;
del[0] = *(m);
del[1] = *(m1);
del[2] = *(m2);
row = i;
}
if (m->content == c)m++;
else if (m1->content == c)m1++;
else m2++;
}
else break;
}
}
if (price != 0) {
mine_comb[row][0].erase(del[0]);
mine_comb[row][1].erase(del[1]);
mine_comb[row][2].erase(del[2]);
mine_comb[2][0].erase(del[0]);
mine_comb[2][1].erase(del[1]);
mine_comb[2][2].erase(del[2]);
res.mCost = price;
res.mContent = content;
}
return res;
}Editor is loading...
Leave a Comment