feat(bfs): new problem formated
This commit is contained in:
97
conversor-fonetico-generico/Makefile
Normal file
97
conversor-fonetico-generico/Makefile
Normal file
@@ -0,0 +1,97 @@
|
||||
# Normal directories
|
||||
SRC_DIR := src
|
||||
BIN_DIR := bin
|
||||
DBG_DIR := bin/debug
|
||||
|
||||
# Grader directories
|
||||
GRADER := $(wildcard $(SRC_DIR)/grader.cpp)
|
||||
GRADER_DIR := $(SRC_DIR)/grader
|
||||
HANDLER_DIR := $(SRC_DIR)/handler
|
||||
|
||||
GRADER_SRC := $(wildcard $(GRADER_DIR)/*.cpp)
|
||||
GRADER_BIN := $(patsubst $(GRADER_DIR)/%.cpp, $(BIN_DIR)/%, $(GRADER_SRC))
|
||||
GRADER_DBG := $(patsubst $(GRADER_DIR)/%.cpp, $(DBG_DIR)/%, $(GRADER_SRC))
|
||||
|
||||
# Change CPP source directories if grader is defined
|
||||
ifdef GRADER
|
||||
SRC := $(wildcard $(HANDLER_DIR)/*.cpp)
|
||||
BIN := $(patsubst $(HANDLER_DIR)/%.cpp, $(BIN_DIR)/%, $(SRC))
|
||||
DBG := $(patsubst $(HANDLER_DIR)/%.cpp, $(DBG_DIR)/%, $(SRC))
|
||||
else
|
||||
SRC := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
BIN := $(patsubst $(SRC_DIR)/%.cpp, $(BIN_DIR)/%, $(SRC))
|
||||
DBG := $(patsubst $(SRC_DIR)/%.cpp, $(DBG_DIR)/%, $(SRC))
|
||||
endif
|
||||
|
||||
SRC_C := $(wildcard $(SRC_DIR)/*.c)
|
||||
BIN_C := $(patsubst $(SRC_DIR)/%.c, $(BIN_DIR)/%, $(SRC_C))
|
||||
DBG_C := $(patsubst $(SRC_DIR)/%.c, $(DBG_DIR)/%, $(SRC_C))
|
||||
|
||||
SRC_JAVA := $(wildcard $(SRC_DIR)/*.java)
|
||||
BIN_JAVA := $(patsubst $(SRC_DIR)/%.java, $(BIN_DIR)/%.class, $(SRC_JAVA))
|
||||
DBG_JAVA := $(patsubst $(SRC_DIR)/%.java, $(DBG_DIR)/%.class, $(SRC_JAVA))
|
||||
|
||||
CHECKER := $(wildcard $(SRC_DIR)/checker.cpp)
|
||||
|
||||
C := gcc
|
||||
CPP := g++
|
||||
CXX_FLAGS := -Wall -O2
|
||||
DEBUG_FLAGS := -Wall -g
|
||||
BOCA_FLAGS := -static -DBOCA_SUPPORT
|
||||
|
||||
JV = javac
|
||||
JV_DEBUG = -g
|
||||
JV_DIR = -d bin
|
||||
JV_DBG_DIR = -d bin/debug
|
||||
|
||||
.PHONY: all debug release checker clean
|
||||
|
||||
all: debug release checker
|
||||
|
||||
debug: $(DBG) $(DBG_C) $(DBG_JAVA) $(GRADER_DBG)
|
||||
|
||||
release: $(BIN) $(BIN_C) $(BIN_JAVA) $(GRADER_BIN)
|
||||
|
||||
ifdef CHECKER
|
||||
checker: $(DBG_DIR)/checker-boca $(BIN_DIR)/checker-boca
|
||||
endif
|
||||
|
||||
$(BIN): $(BIN_DIR)/% : $(SRC_DIR)/%.cpp | $(BIN_DIR)
|
||||
$(CPP) $(CXX_FLAGS) $^ -o $@
|
||||
|
||||
$(DBG): $(DBG_DIR)/% : $(SRC_DIR)/%.cpp | $(DBG_DIR)
|
||||
$(CPP) $(DEBUG_FLAGS) $^ -o $@
|
||||
|
||||
$(BIN_C): $(BIN_DIR)/% : $(SRC_DIR)/%.c | $(BIN_DIR)
|
||||
$(C) $(CXX_FLAGS) $^ -o $@
|
||||
|
||||
$(DBG_C): $(DBG_DIR)/% : $(SRC_DIR)/%.c | $(DBG_DIR)
|
||||
$(C) $(DEBUG_FLAGS) $^ -o $@
|
||||
|
||||
$(BIN_JAVA): $(BIN_DIR)/%.class : $(SRC_DIR)/%.java | $(BIN_DIR)
|
||||
$(JV) $(JV_DIR) $^
|
||||
|
||||
$(DBG_JAVA): $(DBG_DIR)/%.class : $(SRC_DIR)/%.java | $(DBG_DIR)
|
||||
$(JV) $(JV_DEBUG) $(JV_DBG_DIR) $^
|
||||
|
||||
$(GRADER_BIN): $(BIN_DIR)/% : $(GRADER_DIR)/%.cpp $(GRADER) $(GRADER_DIR)/*.h
|
||||
$(CPP) $(CXX_FLAGS) $^ -o $@
|
||||
|
||||
$(GRADER_DBG): $(DBG_DIR)/% : $(GRADER_DIR)/%.cpp $(GRADER) $(GRADER_DIR)/*.h
|
||||
$(CPP) $(DEBUG_FLAGS) $^ -o $@
|
||||
|
||||
$(BIN_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
$(DBG_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
$(BIN_DIR)/checker-boca: $(SRC_DIR)/checker.cpp
|
||||
$(CPP) $(CXX_FLAGS) $(BOCA_FLAGS) $^ -o $@
|
||||
|
||||
$(DBG_DIR)/checker-boca: $(SRC_DIR)/checker.cpp
|
||||
$(CPP) $(DEBUG_FLAGS) $(BOCA_FLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
@echo Cleaning problem files
|
||||
rm -rf bin
|
||||
82
conversor-fonetico-generico/conversor-fonetico-generico.tex
Normal file
82
conversor-fonetico-generico/conversor-fonetico-generico.tex
Normal file
@@ -0,0 +1,82 @@
|
||||
\documentclass{maratona}
|
||||
|
||||
\begin{document}
|
||||
\begin{ProblemaAutor}{}{Conversor Fonético Genérico}{1}{256}{Leetcode 127}
|
||||
|
||||
|
||||
|
||||
Nos laboratórios secretos de linguística computacional do \textbf{Instituto de Filologia Binária (IFB)}, um grupo de pesquisadores (e estagiários desesperados) finalmente concluiu o desenvolvimento do \textit{Conversor Fonético Genérico} (CFG). Este dispositivo revolucionário, que mais parece uma torradeira antiga com fios coloridos, é capaz de transmutar uma palavra em outra por meio de "mutações linguísticas controladas".
|
||||
|
||||
O CFG, no entanto, opera sob regras quânticas muito estritas:
|
||||
|
||||
\begin{enumerate}
|
||||
\item \textbf{Mutação Única:} Em cada etapa da transformação, \textbf{apenas uma letra} da palavra atual pode ser alterada para uma nova letra.
|
||||
\item \textbf{Validação de Realidade:} A nova palavra gerada pela mutação deve ser "real", ou seja, ela \textbf{deve existir} no vasto (e um tanto pedante) dicionário interno da máquina.
|
||||
\end{enumerate}
|
||||
|
||||
Se uma mutação gerar uma palavra que não está no dicionário (um "blabismo vocabular"), a transformação é rejeitada, o fusível principal do CFG queima, e o processo falha catastroficamente.
|
||||
|
||||
Os pesquisadores querem agora otimizar o processo. Eles não querem qualquer transformação; eles precisam encontrar a \textbf{sequência de transformação mais eficiente} — aquela que usa o menor número possível de palavras para ir da palavra inicial até a palavra final.
|
||||
|
||||
|
||||
Dadas duas palavras, \texttt{inicio} e \texttt{fim} (ambas com o mesmo comprimento), e um dicionário de palavras válidas, determine o \textbf{menor número de palavras} na sequência de transformação que converte \texttt{inicio} em \texttt{fim}, obedecendo às regras de mutação do CFG.
|
||||
|
||||
Note que todas as palavras intermediárias na sequência, bem como a palavra \texttt{fim}, devem existir no dicionário. A palavra \texttt{inicio} não precisa estar no dicionário (ela é o ponto de partida).
|
||||
|
||||
Se não for possível realizar a transformação, o CFG deve retornar $0$.
|
||||
|
||||
\Entrada
|
||||
|
||||
A entrada começa com dois inteiros $n$ e $m$, onde $n$ é o número de palavras disponíveis no dicionário ($1 \leq n \leq 5000$) e
|
||||
$m$ o comprimento de cada palavra ($1 \leq m \leq 10$).
|
||||
|
||||
Na segunda linha há duas palavras: \texttt{inicio} e \texttt{fim}, ambas contendo exatamente $m$ letras minúsculas do alfabeto.
|
||||
|
||||
Após isso, seguem $n$ linhas, cada uma contendo uma palavra de $m$ letras minúsculas, representando as palavras do dicionário interno do CFG.
|
||||
Todas as palavras do dicionário são únicas.
|
||||
|
||||
\Saida
|
||||
|
||||
A saída consiste em um único número inteiro: o comprimento da menor sequência de transformação que converte a palavra \texttt{inicio} na palavra \texttt{fim}, seguindo as regras do CFG.
|
||||
|
||||
Se não for possível realizar a transformação, o programa deve imprimir $0$.
|
||||
|
||||
\ExemploEntrada
|
||||
\begin{Exemplo}
|
||||
\texttt{6~3} & \texttt{4}\\
|
||||
\texttt{mao~sol} & \\
|
||||
\texttt{cao} & \\
|
||||
\texttt{sal} & \\
|
||||
\texttt{sao} & \\
|
||||
\texttt{sai} & \\
|
||||
\texttt{mel} & \\
|
||||
\texttt{sol} & \\
|
||||
\rowcolor{gray!20}\texttt{7~4} & \texttt{0}\\
|
||||
\rowcolor{gray!20}\texttt{lata~fogo} & \\
|
||||
\rowcolor{gray!20}\texttt{lido} & \\
|
||||
\rowcolor{gray!20}\texttt{lapa} & \\
|
||||
\rowcolor{gray!20}\texttt{lava} & \\
|
||||
\rowcolor{gray!20}\texttt{fava} & \\
|
||||
\rowcolor{gray!20}\texttt{fogo} & \\
|
||||
\rowcolor{gray!20}\texttt{lago} & \\
|
||||
\rowcolor{gray!20}\texttt{logo} & \\
|
||||
\end{Exemplo}
|
||||
|
||||
|
||||
|
||||
\Notas
|
||||
|
||||
|
||||
Caso de Teste 1:
|
||||
Neste caso, queremos transformar "mao" em "sol".
|
||||
|
||||
O dicionário contém palavras intermediárias que permitem mutações válidas alterando apenas uma letra por vez.
|
||||
Uma possível sequência mínima é:
|
||||
|
||||
mao → sao → sal → sol
|
||||
|
||||
A sequência tem 4 palavras no total.
|
||||
|
||||
Caso de Teste 2:
|
||||
Não é possível converter "lata" em "fogo", portanto a resposta é 0.\end{ProblemaAutor}
|
||||
\end{document}
|
||||
8
conversor-fonetico-generico/input/1
Normal file
8
conversor-fonetico-generico/input/1
Normal file
@@ -0,0 +1,8 @@
|
||||
6 3
|
||||
mao sol
|
||||
cao
|
||||
sal
|
||||
sao
|
||||
sai
|
||||
mel
|
||||
sol
|
||||
9
conversor-fonetico-generico/input/2
Normal file
9
conversor-fonetico-generico/input/2
Normal file
@@ -0,0 +1,9 @@
|
||||
7 4
|
||||
lata fogo
|
||||
lido
|
||||
lapa
|
||||
lava
|
||||
fava
|
||||
fogo
|
||||
lago
|
||||
logo
|
||||
188
conversor-fonetico-generico/maratona.cls
Normal file
188
conversor-fonetico-generico/maratona.cls
Normal file
@@ -0,0 +1,188 @@
|
||||
\ProvidesPackage{maratona}
|
||||
\LoadClass[11pt]{article}
|
||||
|
||||
% remove page numbers
|
||||
\pagenumbering{gobble}
|
||||
|
||||
\RequirePackage{fancyhdr}
|
||||
|
||||
\RequirePackage{tabularx,colortbl}
|
||||
|
||||
%\RequirePackage{arial}
|
||||
\RequirePackage{ifpdf}
|
||||
\RequirePackage[T1]{fontenc}
|
||||
\RequirePackage[utf8]{inputenc}
|
||||
\RequirePackage[portuguese]{babel}
|
||||
\RequirePackage{graphics}
|
||||
\RequirePackage{graphicx}
|
||||
\RequirePackage{amssymb,amsmath,wrapfig}
|
||||
\RequirePackage{xcolor,colortbl}
|
||||
\RequirePackage{xcolor}
|
||||
\RequirePackage{ifthen}
|
||||
\oddsidemargin 0cm
|
||||
\evensidemargin -2cm
|
||||
\topmargin -1cm
|
||||
\textwidth 16cm
|
||||
\textheight 23cm
|
||||
|
||||
\ifpdf
|
||||
\RequirePackage[pdftex]{hyperref}
|
||||
\else
|
||||
\RequirePackage[hypertex]{hyperref}
|
||||
\fi
|
||||
|
||||
|
||||
\newcommand{\var}[1]{\ensuremath{{#1}}}
|
||||
|
||||
|
||||
\hypersetup{
|
||||
letterpaper,
|
||||
colorlinks=true,
|
||||
linkcolor=blue,
|
||||
urlcolor=blue,
|
||||
pdfpagemode=none,
|
||||
pdftitle={IV Maratona de Programação do IFB \today},
|
||||
pdfauthor={},
|
||||
pdfsubject={Caderno de problemas da IV Maratona de Programação do IFB },
|
||||
pdfkeywords={maratona, programação, IFB}
|
||||
}
|
||||
|
||||
|
||||
|
||||
\DeclareGraphicsExtensions{png}
|
||||
|
||||
\lhead{DS Contest Tools}
|
||||
\pagestyle{fancy}
|
||||
|
||||
% Capa
|
||||
\newenvironment{Maratona}[3]
|
||||
{
|
||||
\begin{titlepage}
|
||||
\begin{center}
|
||||
|
||||
\vspace{1cm}
|
||||
\Large{\textbf{#1}} \\
|
||||
\vspace{1cm}
|
||||
{\textbf{Caderno de Problemas}} \\
|
||||
\vspace{1cm}
|
||||
\begin{small}
|
||||
\textsl{#2}
|
||||
\end{small} \\
|
||||
\begin{figure}[htp]
|
||||
\begin{center}
|
||||
\includegraphics[scale=1]{logos/logo-maratona.png}
|
||||
\end{center}
|
||||
\end{figure}
|
||||
{(Este caderno contém {#3} problemas)} \\
|
||||
\vspace{1cm}
|
||||
}
|
||||
{
|
||||
\vfill
|
||||
\begin{small}
|
||||
{QNM 40, Área Especial nº 01,
|
||||
Taguatinga/DF, 72146-000 ,
|
||||
Brasil } \\
|
||||
{Telefone (61) 2103-2200 \\http://www.ifb.edu.br/taguatinga} \\
|
||||
\end{small}
|
||||
\end{center}
|
||||
\end{titlepage}
|
||||
}
|
||||
|
||||
\newcommand{\Organizacao}[2]{
|
||||
{\small \vfill
|
||||
\begin{center}
|
||||
|
||||
\textbf{Comissão Organizadora:} \\
|
||||
{#1} \\
|
||||
\bigskip
|
||||
\textbf{Apoio:}\\
|
||||
{#2}
|
||||
\end{center}
|
||||
}
|
||||
\vfill
|
||||
}
|
||||
|
||||
|
||||
% Problema
|
||||
\newcounter{problem}
|
||||
\newenvironment{Problema}[4]{
|
||||
\stepcounter{problem}
|
||||
\newpage
|
||||
\begin{center}
|
||||
\Large{\ifthenelse{\equal{#1}{}}{\textbf{{#2}}}{\textbf{Problema {#1} -- {#2} }}}{\\\footnotesize \textbf{Limite de tempo: {#3}s}}{\\[-0.1cm]\footnotesize \textbf{Limite de memória: {#4}MB}}
|
||||
\end{center}
|
||||
}
|
||||
|
||||
\newcounter{problemAutor}
|
||||
\newenvironment{ProblemaAutor}[5]{
|
||||
\stepcounter{problemAutor}
|
||||
\newpage
|
||||
\begin{center}
|
||||
\Large{\ifthenelse{\equal{#1}{}}{\textbf{{#2}}}{\textbf{Problema {#1} -- {#2} }}}{\\\footnotesize \textbf{Limite de tempo: {#3}s}}{\\[-0.1cm]\footnotesize \textbf{Limite de memória: {#4}MB\\}}{
|
||||
\footnotesize Autor: {#5}
|
||||
}
|
||||
\end{center}
|
||||
}
|
||||
|
||||
|
||||
% Código-fonte
|
||||
\newcommand{\codigofonte}[1]{Nome do arquivo fonte: {#1}}
|
||||
|
||||
% Entrada
|
||||
\newcommand{\Entrada}{
|
||||
\bigskip
|
||||
\begin{large}
|
||||
\textbf{Entrada} \\
|
||||
\end{large}
|
||||
}
|
||||
|
||||
% Saida
|
||||
\newcommand{\Saida}{
|
||||
\bigskip
|
||||
\begin{large}
|
||||
\textbf{Saída} \\
|
||||
\end{large}
|
||||
}
|
||||
|
||||
\newcommand{\Interacao}{
|
||||
\bigskip
|
||||
\begin{large}
|
||||
\textbf{Interação} \\
|
||||
\end{large}
|
||||
}
|
||||
|
||||
\newcommand{\Notas}{
|
||||
\bigskip
|
||||
\begin{large}
|
||||
\textbf{Notas} \\
|
||||
\end{large}
|
||||
}
|
||||
|
||||
% Exemplo
|
||||
\newenvironment{Exemplo}
|
||||
{
|
||||
|
||||
\tabularx{\textwidth}{XX}
|
||||
% {@{\extracolsep{\fill}}|l|l|}
|
||||
% {|l|l@{\extracolsep{\fill}|}}
|
||||
\hline
|
||||
Entrada & Saída \\\hline
|
||||
}
|
||||
{
|
||||
\hline
|
||||
\endtabularx
|
||||
}
|
||||
|
||||
% Exemplo de Entrada
|
||||
\newenvironment{ExemploEntrada}
|
||||
{
|
||||
\bigskip
|
||||
\begin{large}
|
||||
\textbf{Exemplo} \\
|
||||
\end{large}
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
% Sample Output
|
||||
|
||||
1
conversor-fonetico-generico/output/1
Normal file
1
conversor-fonetico-generico/output/1
Normal file
@@ -0,0 +1 @@
|
||||
4
|
||||
1
conversor-fonetico-generico/output/2
Normal file
1
conversor-fonetico-generico/output/2
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
64
conversor-fonetico-generico/problem.json
Normal file
64
conversor-fonetico-generico/problem.json
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"problem": {
|
||||
"title": "Conversor Fonético Genérico",
|
||||
"event": "",
|
||||
"time_limit": 1.0,
|
||||
"memory_limit_mb": 256,
|
||||
"input_file": "stdin",
|
||||
"output_file": "stdout",
|
||||
"interactive": false,
|
||||
"grader": false,
|
||||
"subject": {
|
||||
"en_us": [
|
||||
"hash-table", "string", "breadth-first-search", "BFS"
|
||||
],
|
||||
"pt_br": [
|
||||
"busca-em-profundidade", "tabela-hash"
|
||||
],
|
||||
"es": [
|
||||
""
|
||||
]
|
||||
}
|
||||
},
|
||||
"author": {
|
||||
"name": "Leetcode 127",
|
||||
"affiliation": "",
|
||||
"country": "",
|
||||
"email": ""
|
||||
},
|
||||
"build": {
|
||||
"run_generator": true,
|
||||
"run_validator": true,
|
||||
"produce_outputs": true,
|
||||
"run_checker": true,
|
||||
"run_all_solutions": true,
|
||||
"run_specific_solution": "",
|
||||
"generate_io_only": false,
|
||||
"generate_pdf_only": false,
|
||||
"cpu_count": 1,
|
||||
"build_pdf": true,
|
||||
"pdf_format": "ds",
|
||||
"io_samples": 2
|
||||
},
|
||||
"solutions": {
|
||||
"main-ac": "ac.cpp",
|
||||
"alternative-ac": [],
|
||||
"wrong-answer": [],
|
||||
"time-limit": [],
|
||||
"time-limit-or-ac": [],
|
||||
"time-limit-or-memory-limit": [],
|
||||
"memory-limit": [],
|
||||
"presentation-error": [],
|
||||
"runtime-error": []
|
||||
},
|
||||
"polygon_config": {
|
||||
"id": ""
|
||||
},
|
||||
"boca_config": {
|
||||
"time_limit": 1,
|
||||
"number_of_repetitions": 1,
|
||||
"maximum_memory_mb": 512,
|
||||
"maximum_output_size_kb": 24096
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
21
conversor-fonetico-generico/statement/description.tex
Normal file
21
conversor-fonetico-generico/statement/description.tex
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
Nos laboratórios secretos de linguística computacional do \textbf{Instituto de Filologia Binária (IFB)}, um grupo de pesquisadores (e estagiários desesperados) finalmente concluiu o desenvolvimento do \textit{Conversor Fonético Genérico} (CFG). Este dispositivo revolucionário, que mais parece uma torradeira antiga com fios coloridos, é capaz de transmutar uma palavra em outra por meio de "mutações linguísticas controladas".
|
||||
|
||||
O CFG, no entanto, opera sob regras quânticas muito estritas:
|
||||
|
||||
\begin{enumerate}
|
||||
\item \textbf{Mutação Única:} Em cada etapa da transformação, \textbf{apenas uma letra} da palavra atual pode ser alterada para uma nova letra.
|
||||
\item \textbf{Validação de Realidade:} A nova palavra gerada pela mutação deve ser "real", ou seja, ela \textbf{deve existir} no vasto (e um tanto pedante) dicionário interno da máquina.
|
||||
\end{enumerate}
|
||||
|
||||
Se uma mutação gerar uma palavra que não está no dicionário (um "blabismo vocabular"), a transformação é rejeitada, o fusível principal do CFG queima, e o processo falha catastroficamente.
|
||||
|
||||
Os pesquisadores querem agora otimizar o processo. Eles não querem qualquer transformação; eles precisam encontrar a \textbf{sequência de transformação mais eficiente} — aquela que usa o menor número possível de palavras para ir da palavra inicial até a palavra final.
|
||||
|
||||
|
||||
Dadas duas palavras, \texttt{inicio} e \texttt{fim} (ambas com o mesmo comprimento), e um dicionário de palavras válidas, determine o \textbf{menor número de palavras} na sequência de transformação que converte \texttt{inicio} em \texttt{fim}, obedecendo às regras de mutação do CFG.
|
||||
|
||||
Note que todas as palavras intermediárias na sequência, bem como a palavra \texttt{fim}, devem existir no dicionário. A palavra \texttt{inicio} não precisa estar no dicionário (ela é o ponto de partida).
|
||||
|
||||
Se não for possível realizar a transformação, o CFG deve retornar $0$.
|
||||
7
conversor-fonetico-generico/statement/input.tex
Normal file
7
conversor-fonetico-generico/statement/input.tex
Normal file
@@ -0,0 +1,7 @@
|
||||
A entrada começa com dois inteiros $n$ e $m$, onde $n$ é o número de palavras disponíveis no dicionário ($1 \leq n \leq 5000$) e
|
||||
$m$ o comprimento de cada palavra ($1 \leq m \leq 10$).
|
||||
|
||||
Na segunda linha há duas palavras: \texttt{inicio} e \texttt{fim}, ambas contendo exatamente $m$ letras minúsculas do alfabeto.
|
||||
|
||||
Após isso, seguem $n$ linhas, cada uma contendo uma palavra de $m$ letras minúsculas, representando as palavras do dicionário interno do CFG.
|
||||
Todas as palavras do dicionário são únicas.
|
||||
13
conversor-fonetico-generico/statement/notes.tex
Normal file
13
conversor-fonetico-generico/statement/notes.tex
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
Caso de Teste 1:
|
||||
Neste caso, queremos transformar "mao" em "sol".
|
||||
|
||||
O dicionário contém palavras intermediárias que permitem mutações válidas alterando apenas uma letra por vez.
|
||||
Uma possível sequência mínima é:
|
||||
|
||||
mao → sao → sal → sol
|
||||
|
||||
A sequência tem 4 palavras no total.
|
||||
|
||||
Caso de Teste 2:
|
||||
Não é possível converter "lata" em "fogo", portanto a resposta é 0.
|
||||
3
conversor-fonetico-generico/statement/output.tex
Normal file
3
conversor-fonetico-generico/statement/output.tex
Normal file
@@ -0,0 +1,3 @@
|
||||
A saída consiste em um único número inteiro: o comprimento da menor sequência de transformação que converte a palavra \texttt{inicio} na palavra \texttt{fim}, seguindo as regras do CFG.
|
||||
|
||||
Se não for possível realizar a transformação, o programa deve imprimir $0$.
|
||||
0
conversor-fonetico-generico/statement/preamble.tex
Normal file
0
conversor-fonetico-generico/statement/preamble.tex
Normal file
0
conversor-fonetico-generico/statement/tutorial.tex
Normal file
0
conversor-fonetico-generico/statement/tutorial.tex
Normal file
Reference in New Issue
Block a user