Browse Source

Stuff.

master
Nicolas Hafner 2 years ago
parent
commit
9a3545a293
Signed by: shinmera GPG Key ID: E12B14478BE4C922
8 changed files with 65 additions and 37 deletions
  1. +7
    -1
      .gitignore
  2. +19
    -0
      doc/doc.tex
  3. +1
    -1
      run.lisp
  4. BIN
      week2/russia/solution.pdf
  5. BIN
      week3/firsthit/solution-firsthit.pdf
  6. BIN
      week5/planks/solution.pdf
  7. BIN
      week6/london/london
  8. +29
    -35
      week6/london/london.cpp

+ 7
- 1
.gitignore View File

@ -4,4 +4,10 @@ CMakeCache.txt
CMakeLists.txt
cmake_install.cmake
Makefile
*.zip
*.zip
doc/doc.aux
doc/doc.log
doc/doc.synctex.gz
doc/doc.pdf
doc/_minted-doc
doc/auto

+ 19
- 0
doc/doc.tex View File

@ -0,0 +1,19 @@
\documentclass{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage{minted}
\usemintedstyle[c++]{emacs}
\renewcommand{\theFancyVerbLine}{{\large \oldstylenums{\arabic{FancyVerbLine}}}}
\begin{document}
\inputminted[linenos]{c++}{../week6/london/london.cpp}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-command-extra-options: "-shell-escape"
%%% TeX-master: t
%%% TeX-engine: luatex
%%% End:

+ 1
- 1
run.lisp View File

@ -69,7 +69,7 @@ set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wall -pedantic\")
(when (loop for in in (sort (mapcar #'sb-ext:native-namestring ins) #'string<)
for out in (sort (mapcar #'sb-ext:native-namestring outs) #'string<)
do (format T "~& --> Test ~a~%" in)
always (test exec in out))
(test exec in out))
(format T "~& --> Submission source:~%~%")
(print-source source)))))

BIN
week2/russia/solution.pdf (Stored with Git LFS) View File

size 213317

BIN
week3/firsthit/solution-firsthit.pdf (Stored with Git LFS) View File

size 194007

BIN
week5/planks/solution.pdf (Stored with Git LFS) View File

size 185469

BIN
week6/london/london View File


+ 29
- 35
week6/london/london.cpp View File

@ -5,9 +5,8 @@
// Graph Type with nested interior edge properties for flow algorithms
typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::directedS> traits;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_capacity_t, int,
boost::property<boost::edge_residual_capacity_t, int,
boost::property<boost::edge_reverse_t, traits::edge_descriptor>>>> graph;
boost::property<boost::edge_capacity_t, int, boost::property<boost::edge_residual_capacity_t, int,
boost::property<boost::edge_reverse_t, traits::edge_descriptor>>>> graph;
typedef traits::vertex_descriptor vertex_desc;
typedef traits::edge_descriptor edge_desc;
@ -29,6 +28,8 @@ public:
int main(){
setup();
int offset = 'A';
int letters = 'Z' - 'A';
auto t = read1<int>();
while(0 < t--){
@ -36,51 +37,44 @@ int main(){
auto w = read1<int>();
auto note = read1<std::string>();
int n = note.size();
graph G(2+n+h*w);
graph G(2+letters+h*w);
edge_adder adder(G);
int counter = 2;
// Edge to target
for(int i=0; i<n; ++i){
adder.add_edge(counter++, 1, 1);
auto source = boost::vertex(0, G);
auto target = boost::vertex(1, G);
// Edge for every letter (letter -> target [num])
for(int i=0; i<letters; ++i){
// Count letters
int count = 0;
for(int j=0; j<n; ++j)
if(note[j]-offset == i) ++count;
if(0 < count)
adder.add_edge(2+i, target, count);
}
// Edge from source
for(int i=0; i<h*w; ++i){
adder.add_edge(0, counter++, 1);
}
// Edge for every snippet (source -> snippet [1])
for(int i=0; i<h*w; ++i)
adder.add_edge(source, 2+letters+i, 1);
// Front vertex
int off = n+2;
// Connect snippet to front letter (snippet -> letter [1])
for(int i=0; i<h; ++i){
auto line = read1<std::string>();
for(int j=0; j<w; ++j){
char c = line[j];
for(int k=0; k<n; ++k){
if(note[k] == c)
adder.add_edge(off+i*w+j, k+2, 1);
}
}
for(int j=0; j<w; ++j)
adder.add_edge(2+letters+i*w+j, line[j]+2-offset, 1);
}
// Back vertex
// Connect snippet to back letter (snippet -> letter [1])
for(int i=0; i<h; ++i){
auto line = read1<std::string>();
for(int j=0; j<w; ++j){
char c = line[j];
for(int k=0; k<n; ++k){
if(note[k] == c)
adder.add_edge(off+i*w+j, k+2, 1);
}
}
for(int j=0; j<w; ++j)
adder.add_edge(2+letters+i*w+(w-j-1), line[j]+2-offset, 1);
}
// if(t==0){
// boost::write_graphviz(std::cout, G);
// return 0;
// }
auto flow = boost::push_relabel_max_flow(G, boost::vertex(0, G), boost::vertex(1, G));
// boost::write_graphviz(std::cout, G);
// return 0;
auto flow = boost::push_relabel_max_flow(G, source, target);
std::cout << ((flow == n)? "Yes" : "No") << '\n';
}
}

Loading…
Cancel
Save