feat(queue): new queue problem formated
This commit is contained in:
62
o-problema-dos-pacotes-viajantes/src/ac.cpp
Normal file
62
o-problema-dos-pacotes-viajantes/src/ac.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define sz(x) ((int)x.size())
|
||||
|
||||
void solve()
|
||||
{
|
||||
int N, S, Q;
|
||||
cin >> N >> S >> Q;
|
||||
vector<queue<int>> cargoes(N);
|
||||
int totalCargoes = 0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
int q;
|
||||
cin >> q;
|
||||
totalCargoes += q;
|
||||
for (int j = 0; j < q; j++)
|
||||
{
|
||||
int c;
|
||||
cin >> c;
|
||||
cargoes[i].push(c - 1);
|
||||
}
|
||||
}
|
||||
|
||||
stack<int> carrier;
|
||||
int station = 0, totalTime = 0;
|
||||
for (int cargoesDelivered = 0; cargoesDelivered < totalCargoes;)
|
||||
{
|
||||
while (!carrier.empty() && (carrier.top() == station || sz(cargoes[station]) < Q))
|
||||
{
|
||||
if (carrier.top() == station)
|
||||
{
|
||||
cargoesDelivered++;
|
||||
}
|
||||
else
|
||||
{
|
||||
cargoes[station].push(carrier.top());
|
||||
}
|
||||
carrier.pop();
|
||||
totalTime++;
|
||||
}
|
||||
while (!cargoes[station].empty() && sz(carrier) < S)
|
||||
{
|
||||
carrier.push(cargoes[station].front());
|
||||
cargoes[station].pop();
|
||||
totalTime++;
|
||||
}
|
||||
station = (station + 1) % N;
|
||||
if (cargoesDelivered < totalCargoes)
|
||||
totalTime += 2; // move to next station
|
||||
}
|
||||
|
||||
cout << totalTime << endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t; cin >> t;
|
||||
while (t--) solve();
|
||||
return 0;
|
||||
}
|
||||
19
o-problema-dos-pacotes-viajantes/src/checker.cpp
Normal file
19
o-problema-dos-pacotes-viajantes/src/checker.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
setName("compare two signed int%d's", 8 * int(sizeof(int)));
|
||||
registerTestlibCmd(argc, argv);
|
||||
|
||||
int ja = ans.readInt();
|
||||
int pa = ouf.readInt();
|
||||
|
||||
if (ja != pa)
|
||||
quitf(_wa, "expected %d, found %d", ja, pa);
|
||||
|
||||
quitf(_ok, "answer is %d", ja);
|
||||
}
|
||||
83
o-problema-dos-pacotes-viajantes/src/generator.cpp
Normal file
83
o-problema-dos-pacotes-viajantes/src/generator.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MIN_N = 0;
|
||||
const int MAX_N = 100;
|
||||
|
||||
const int rnd_test_n = 100;
|
||||
|
||||
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
|
||||
dest.insert(dest.end(), orig.begin(), orig.end());
|
||||
}
|
||||
|
||||
string output_tc(int x, int y) {
|
||||
ostringstream oss;
|
||||
oss << x << " " << y << endl;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(1, 1));
|
||||
tests.push_back(output_tc(2, 2));
|
||||
tests.push_back(output_tc(0, 0));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<string> generate_manual_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(100, 0));
|
||||
tests.push_back(output_tc(0, 100));
|
||||
return tests;
|
||||
}
|
||||
|
||||
string rnd_test(int i){
|
||||
int min_n = MIN_N;
|
||||
int max_n = MAX_N;
|
||||
|
||||
if(i<rnd_test_n / 3){
|
||||
max_n = 5;
|
||||
}
|
||||
else if(i<rnd_test_n / 2){
|
||||
max_n = 20;
|
||||
}
|
||||
|
||||
int x = rnd.next(min_n, max_n);
|
||||
int y = rnd.next(min_n, max_n);
|
||||
return(output_tc(x, y));
|
||||
}
|
||||
|
||||
vector<string> generate_random_tests() {
|
||||
vector<string> tests;
|
||||
for (int i = 0; i < rnd_test_n; i++){
|
||||
tests.push_back(rnd_test(i));
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
|
||||
string extreme_test_1(){
|
||||
return(output_tc(100, 100));
|
||||
}
|
||||
|
||||
vector<string> generate_extreme_tests(){
|
||||
vector<string> tests;
|
||||
tests.push_back(extreme_test_1());
|
||||
return tests;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
registerGen(argc, argv, 1);
|
||||
vector<string> tests;
|
||||
size_t test = 0;
|
||||
append(tests, generate_sample_tests());
|
||||
append(tests, generate_manual_tests());
|
||||
append(tests, generate_random_tests());
|
||||
append(tests, generate_extreme_tests());
|
||||
for (const auto &t : tests) {
|
||||
startTest(++test);
|
||||
cout << t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
o-problema-dos-pacotes-viajantes/src/script.sh
Normal file
1
o-problema-dos-pacotes-viajantes/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
o-problema-dos-pacotes-viajantes/src/testlib.h
Normal file
5963
o-problema-dos-pacotes-viajantes/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
33
o-problema-dos-pacotes-viajantes/src/validator.cpp
Normal file
33
o-problema-dos-pacotes-viajantes/src/validator.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
|
||||
int t = inf.readInt(1, 100, "t");
|
||||
inf.readEoln();
|
||||
for (int i = 0; i < t; i++) {
|
||||
int n = inf.readInt(2, 100);
|
||||
inf.readSpace();
|
||||
int s = inf.readInt(1, 100);
|
||||
inf.readSpace();
|
||||
int q = inf.readInt(1, 100);
|
||||
inf.readEoln();
|
||||
|
||||
for (int j = 1; j <= n; j++) {
|
||||
int cargoes = inf.readInt(0, q, "cargoes");
|
||||
for (int k = 1; k <= cargoes; k++) {
|
||||
inf.readSpace();
|
||||
int destination = inf.readInt(1, n, "destination");
|
||||
ensuref(j != destination, "Cargoe cannot have its station as its destination");
|
||||
}
|
||||
inf.readEoln();
|
||||
}
|
||||
}
|
||||
inf.readEof();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user