Monday, November 16, 2015

(Computational?) Geometry problems from POJ


Here's a short list of some mixed geometry flavored problems from POJ.

1039106611131151117712281254126312691385138914081410
1556158416961765181918371873203120432074207921652187
2242228023182354239824202423254026532826295429663004
3130322732773304333533473348338434293449352536083695

There is a possibility that some of these may not be geometry problem at all, tried my best to sort them out though. Also, some of these problems are not solvable by only geometry knowledge. Graph, dynamic programming, and understanding of advanced data structure may also be required.


Maximum Flow and BPM Problems from SPOJ and HDU


Here is a short list of network flow and bpm problems that I managed to solve from SPOJ and HDU. This is not much and there are other sources of these kinds of problems, but I think these are some good starting points. Also I did not classify them on the types of flow or bpm, that would be up to the reader.

Maximum Flow and Bipartite Matching problems from SPOJ

ANGELSBABYDIVRELFASTFLOWMATCHING
MSE06IMTOTALFMUDDYPCPC12HPROFIT
PT07XQUEST4SCITIESSTEADTAXI

Maximum Flow and Bipartite Matching problems from HDU

15321533185324482686
27322833308132773315
33763395341634193435
34683472348834913572
36673987399841834309

Note: UVa has a lot of flow and bpm problems, please visit uHunt for guidelines.

Note: It is very possible that there are many other problems from these online judges which can be solved by flow or bpm algorithms. And, some problems here could be mistakenly added as flow or bpm category due to copy paste errors. Please feel free to leave a note on the comment section, add more links if you like to. Happy coding \m/


Thursday, October 1, 2015

Ajax Queue Example Code


Although this is not what ajax is meant for, but sometimes application requirements force us to implement various hacks. For example, ajax is usually done for light-weight request. But in my case, I am using it for an alternative to form submission. Each of these submissions causes heavy load at server end. So I cannot allow more than one concurrent ajax call to reach the server. This simple solution worked as a charm.

Javascript code:

var ajaxQueue = $({});
var currentRequest = null;
$.ajaxQueue = function( ajaxOpts ) {
    // Hold the original complete function.
    var oldComplete = ajaxOpts.complete;
    // Queue our ajax request.
    ajaxQueue.queue(function( next ) {
        // Create a complete callback to fire the next event in the queue.
        ajaxOpts.complete = function() {
            // Fire the original complete if it was there.
            if ( oldComplete ) {
                oldComplete.apply( this, arguments );
            }
            // Run the next query in the queue.
            next();
        };
        // Run the query.
        currentRequest = $.ajax( ajaxOpts );
    });
};

// Ajax calls
function ajaxCall() {
    $.ajaxQueue({
        type: "POST",
        url: '/echo/json/',
        async: true,
        cache: false,
        success: function( result ) {
            // process response
        }
    });
}

// Abort method
function abortAjaxQueue() {
    ajaxQueue.clearQueue();
    if (currentRequest) {
        currentRequest.abort();
    }
}

Disclaimer

This is not my own code, this is community developed, thanks to this stackoverflow question and its accepted answer by sroes. Tested using JQuery versions 1.9.1 to 2.3.1

Play with this code in JSFiddle


Saturday, June 27, 2015

Dynamic Programming (DP) problems from SPOJ


Sphere Online Judge a.k.a. SPOJ is a very good online judge. Still, beginners face a lot of trouble when they first come to SPOJ, mainly because SPOJ is not as well categorized as some other judges out there. Recently SPOJ is trying to offer problem hints, but due to being community driven, this is still a long shot. Classification hints for SPOJ problems are not commonly available in the internet as well. So far I have managed to solve a few dynamic problems from SPOJ and I think for someone who is trying to practice dynamic programming problems from SPOJ, this short list might come handy.

ACMAKEREDISTMBLASTRAINBOW
ACODEEQ2MCARDSRENT
ACPC10DFISHERMDOLLSROCK
ACPC10GFPOLICEMISERMANSAMER08C
AIBOHPGCPC11BMIXTURESSCUBADIV
ANARC05BGNY07HMMAXPERSOLDIER
ANARC05HGNYR09FMPILOTSQRBR
ARBITRAGHANGOVERMREPLBRCSTONE2
BABTWRHELPBOBNOCHANGETEMPTISL
BYTESM2HIST2NUMPLAYTOURIST
CHAIRIKEYBNY10ETRAVERSE
COINSINGREDOSPROB1TRIKA
COUNTIOIPALINPARTITTRIP
CPRMTJRIDEPARTYTRT
CRSCNTRYKNAPSACKPCPC12GTWENDS
CSUBSEQSLINEUPPEGSUPSUB
CZ_PROB1M3TILEPERMUT1VOCV
DCEPC501MAIN112PHIDIASWPC4F
DINGRPMAIN113PIGBANKZUMA
DSUBSEQMARTIANPIZZALOC 
DTTMAXSUMSQPSTRING 

Please feel free to add more in the comments. Thanks