ZOJ is an online judge system maintained by Zhejiang University ACM/ICPC Team. It allows people to solve algorithm problems online.
This repo contains the solutions for ZOJ problems written by daseinpwt. The solutions include the C++ source codes and the problem analyses in pdf format.
A solution framework is developed to accelerate coding and documenting.
Sometime we might want to have some utility data structures and functions in separate header files, to keep the code well organised and easy to maintain. However, ZOJ (actually, almost all the OJs) only supports single C/C++ source file. That means you can not use own header files and you need to copy-paste all the utility functions every time you code for a new problem.
What would be really convenient is:
- We can write our own utility functions in separate header files and use
#include
to compile, run and test the code locally. - When we want to submit the code, the included header files will be automatically inline-replaced.
Inspired by Using a C preprocessor as an HTML authoring tool, this idea is implemented by taking advantage of the gcc preprocessor.
To see the detail of the trick, check cpp.tpl
and the dist
target in Makefile.tpl
(The tool awk
is used in Makefile instead of sed
because MacOS and Linux use different versions of sed
).
By using pandoc
, we can write text in markdown and latex. You can check Easy LaTeX with Markdown and Pandoc for a quick look.
When we run create
, a file solution.md
is automatically generated in the problem folder and you can use make solution
to generate a corresponding pdf file.
- In root directory,
./create {Problem Number}
- In the created folder, add your own header files (if any) and solution code to
{Problem Number}.cpp
make run
. The code ({Problem Number}.cpp
) will be compiled and executed- If you want to compare the program with some standard solution (the AC code), you need to copy-paste the standard solution into
std.cpp
and write code for generating test data inmake_data.py
. After that, you can runmake check
to start the automated checking. When a input which yields different outputs is found, the checking will be terminated and you can find the corresponding input and outputs in the foldercheck
make dist
. A file{Problem Number}_dist.cpp
will be generated under the folderbuild
. You can use that file for submission- After AC, you might want to write down your solution. You can do it in
solution.md
and use both markdown and latex grammars. Runmake solution
to generate a corresponding pdf file
C++11 features are used in some places. It is always safe to compile the programs with '-std=c++11' flag.