четвер, 14 листопада 2013 р.

UVa Online Judge CLI Utilitites

For those who are unfamiliar, UVa Online Judge is a very good but somewhat dated platform for online programming contests and practicing in competitive programming.

I've been practicing in solving competitive programming problems (that is mainly algorithmic problems) using an excellent book by Steven and Felix Halim, which is the reason why I use this particular OJ - since the book gives a course of competitive programming techniques and exercises relying on the problemset presented on UVa OJ. So if you are like me and occasionally solve some problems from UVa OJ - this below CLI utilities might be useful to you to save some time.

The problems at UVa OJ do not have nice perma-links which would contain the ID of the problem.  So for example the problem with ID 11232 has a link http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2173 - not very convenient.  It is of course possible to navigate thru the Problem catalog, find the needed volume and open the problem, but this takes several seconds or even minutes of precious time, and given you have to do it often - this will end up eating a lot of your time.

My solution is dead simple: we parse all of the problemset volumes and create a database table with a map of problem ID's to their corresponding links (and titles).  For this you would need a local database server (I used MySQL).
CREATE TABLE `problems` (
  `problem_id` varchar(5) NOT NULL,
  `problem_title` varchar(256) DEFAULT NULL,
  `problem_url` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`problem_id`)

Based on this database table we are now able to
a) open any problem by ID
b) retrieve any problem's title by ID

All of the utilities are in this repo: https://github.com/justadreamer/uva-solutions

The utility that is responsible for parsing out the data is called:  crawler.py

You would need to setup MySQL db with the schema mentioned above and specify it in the db.cfg file (there is a db.cfg.example in the same repository to show you an example of the settings, just replace it with your own settings).

crawler.py would need to be run periodically, because UVa OJ occasionally adds new problems.

There are other useful utilities.  The one that I use to open problems (works on Mac OS X) is open.py, and the other one that I use to submit problems from the command line is submit.py.  You are welcome to check out and suggest improvements/modifications to these tools.

Немає коментарів:

Дописати коментар