Untitled
unknown
plain_text
a year ago
2.3 kB
16
Indexable
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int fee;
struct stone{
int id;
int cost;
int content;
int type;
stone(int id, int type, int cost, int content) {
this->id = id;
this->cost = cost;
this->content = content;
this->type = type;
}
};
stone del0 = stone(0, 0, 0, 0);
stone del1 = stone(0, 0, 0, 0);
stone del2 = stone(0, 0, 0, 0);
struct cmp{
bool operator()(stone a, stone b) {
return a.cost < b.cost;
}
};
set<stone, cmp> table[3][3];
struct Result {
int mCost;
int mContent;
};
void init(int mShipFee) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
table[i][j].clear();
}
}
fee = mShipFee;
}
int gather(int mMineId, int mType, int mCost, int mContent) {
stone tmp = stone(mMineId, mType, mCost, mContent);
table[mMineId][mType].insert(tmp);
table[2][mType].insert(tmp);
return 0;
}
Result mix(int mBudget) {
int row;
Result res = {0, 0};
int contentRes = -1;
int costRes = 99999999;
int contentCur, costCur;
for(int i=0; i<3; i++) {
auto stone0 = table[i][0].begin();
auto stone1 = table[i][1].begin();
auto stone2 = table[i][2].begin();
while(stone0 != table[i][0].end() && stone1 != table[i][1].end() && stone2 != table[i][2].end()) {
if(i!=2) {
costCur = stone0->cost + stone1->cost + stone2->cost + fee;
} else {
costCur = stone0->cost + stone1->cost + stone2->cost + 2 * fee;
}
if(costCur <= mBudget) {
contentCur = min(stone0->content, stone1->content, stone2->content);
if(contentCur > contentRes || costCur < costRes) {
contentRes = contentCur;
costRes = costCur;
del0 = stone(stone0->id, stone0->type, stone0->cost, stone0->content);
del1 = stone(stone1->id, stone1->type, stone1->cost, stone1->content);
del2 = stone(stone2->id, stone2->type, stone2->cost, stone2->content);
row = i;
}
}
if(stone0->content == contentCur) stone0++;
else if(stone1->content == contentCur) stone1++;
else stone2++;
}
}
table[row][0].erase(del0);
table[row][1].erase(del1);
table[row][2].erase(del2);
table[2][0].erase(del0);
table[2][1].erase(del1);
table[2][2].erase(del2);
}
Editor is loading...
Leave a Comment