feat(bfs): new problem formated
This commit is contained in:
72
conversor-fonetico-generico/src/ac.cpp
Normal file
72
conversor-fonetico-generico/src/ac.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
string beginWord, endWord;
|
||||
cin >> beginWord >> endWord;
|
||||
|
||||
unordered_set<string> words;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
words.insert(s);
|
||||
}
|
||||
words.insert(beginWord);
|
||||
|
||||
unordered_map<string, list<string>> adj;
|
||||
for (auto &word : words)
|
||||
{
|
||||
for (int j = 0; j < m; j++)
|
||||
{
|
||||
string aux = word;
|
||||
for (char c = 'a'; c <= 'z'; c++)
|
||||
{
|
||||
aux[j] = c;
|
||||
if (words.count(aux))
|
||||
{
|
||||
adj[word].push_back(aux);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
queue<string> q;
|
||||
unordered_set<string> seen;
|
||||
q.push(beginWord);
|
||||
seen.insert(beginWord);
|
||||
|
||||
int depth = 1;
|
||||
while (!q.empty())
|
||||
{
|
||||
int nodes = q.size();
|
||||
while (nodes--)
|
||||
{
|
||||
string s = q.front();
|
||||
q.pop();
|
||||
|
||||
if (s == endWord)
|
||||
{
|
||||
cout << depth << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (auto &t : adj[s])
|
||||
{
|
||||
if (!seen.count(t))
|
||||
{
|
||||
q.push(t);
|
||||
seen.insert(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
depth++;
|
||||
}
|
||||
|
||||
cout << 0 << endl;
|
||||
return 0;
|
||||
}
|
||||
19
conversor-fonetico-generico/src/checker.cpp
Normal file
19
conversor-fonetico-generico/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);
|
||||
}
|
||||
92
conversor-fonetico-generico/src/generator.cpp
Normal file
92
conversor-fonetico-generico/src/generator.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
string my_output_tc(int n, int m, const string &s, const string &e, const vector<string>& dict) {
|
||||
ostringstream oss;
|
||||
oss << n << " " << m << endl;
|
||||
oss << s << " " << e << endl;
|
||||
for (auto &s : dict) {
|
||||
oss << s << endl;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(my_output_tc(6, 3, "mao", "sol", {"cao", "sal", "sao", "sai", "mel", "sol"}));
|
||||
tests.push_back(my_output_tc(7, 4, "lata", "fogo", {"lido", "lapa", "lava", "fava", "fogo", "lago", "logo"}));
|
||||
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
conversor-fonetico-generico/src/script.sh
Normal file
1
conversor-fonetico-generico/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
conversor-fonetico-generico/src/testlib.h
Normal file
5963
conversor-fonetico-generico/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
31
conversor-fonetico-generico/src/validator.cpp
Normal file
31
conversor-fonetico-generico/src/validator.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
|
||||
int n = inf.readInt(1, 5000, "n");
|
||||
inf.readSpace();
|
||||
int m = inf.readInt(1, 10, "m");
|
||||
inf.readEoln();
|
||||
|
||||
string wordPattern = "[a-z]{" + to_string(m) + "}";
|
||||
string start = inf.readToken(wordPattern, "palavraInicial");
|
||||
inf.readSpace();
|
||||
string end = inf.readToken(wordPattern, "palavraFinal");
|
||||
inf.readEoln();
|
||||
|
||||
unordered_set<string> seen;
|
||||
for (int i = 0; i < n; i++) {
|
||||
string s = inf.readToken(wordPattern);
|
||||
ensuref(seen.count(s) == 0, "As palavras do dicionario do CFG devem ser unicas");
|
||||
seen.insert(s);
|
||||
inf.readEoln();
|
||||
}
|
||||
inf.readEof();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user