#include "scales.h"
#include <bits/stdc++.h>
using namespace std;
void init(int T) {}
/*
int getMedian(int A, int B, int C);
int getHeaviest(int A, int B, int C);
int getLightest(int A, int B, int C);
int getNextLightest(int A, int B, int C, int D);
*/
// Olhar como é na STL
void put(vector<int>& v, int i, int val) {
vector<int> res;
for (int j=0; j<i; j++) res.push_back(v[j]);
res.push_back(val);
for (int j=i; j<(int)v.size(); j++) {
res.push_back(v[j]);
}
swap(v, res);
}
void rem(vector<int>&v, int val) {
vector<int> res;
for (int i=0; i<(int)v.size(); i++) {
if (v[i] != val) res.push_back(v[i]);
}
swap(res, v);
}
void orderCoins() {
int a, b, A, B;
int c = getLightest(1, 2, 3);
if (c == 1) a = 2, b = 3;
else if (c == 2) a = 1, b = 3;
else a = 1, b = 2;
int C = getLightest(4, 5, 6);
if (C == 4) A = 5, B = 6;
else if (C == 5) A = 4, B = 6;
else A = 4, B = 5;
int ans[6];
ans[0] = getLightest(c, C, a);
vector<int> tmp;
if (ans[0] == c) {
tmp = vector<int> {A, B};
ans[1] = getLightest(C, a, b);
if (ans[1] != C) tmp.push_back(C);
if (ans[1] != a) tmp.push_back(a);
if (ans[1] != b) tmp.push_back(b);
} else {
tmp = vector<int> {a, b};
ans[1] = getLightest(c, A, B);
if (ans[1] != c) tmp.push_back(c);
if (ans[1] != A) tmp.push_back(A);
if (ans[1] != B) tmp.push_back(B);
}
int l = getLightest(tmp[0], tmp[1], tmp[2]);
rem(tmp, l); // TODO: certo?
ans[5] = getHeaviest(tmp[0], tmp[1], tmp[2]);
rem(tmp, ans[5]);
tmp.push_back(l);
ans[2] = getLightest(tmp[0], tmp[1], tmp[2]);
ans[3] = getMedian(tmp[0], tmp[1], tmp[2]);
ans[4] = tmp[0] + tmp[1] + tmp[2] - ans[2] - ans[3];
answer(ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |