Friday, February 10, 2012

Getting Started With uvaonlinejudge ...

What is uva online judge after all ???

According to wikipedia , UVa Online Judge is an online automated judge for programming problems . The system can compile and execute codes and test them with pre-constructed data. Submitted code may be run with restrictions, including time limit, memory limit, security restriction and so on. The output of the code will be captured by the system, and compared with the standard output. It will then inform you whether your solutions are correct (AC) , or faulty and in the latter case it will also tell you what the problem was viz..

  • Your code could not be compiled on their compiler ,

  • Your code did not produce the correct output for all the test cases they tried (WA) ,

  • Presentation error - you did not display the output the way they expect you to  etc.....


The registration is open to all users (and free of cost too :D).  A user may submit a solution in C, C++, Java or Pascal.  You just have to get yourself registered at the site .

Solving a problem on the UVa Online Judge requires the following:

  • Read and understand the problem statement .

  • Devise an algorithm (may vary from a very simple one to an extremely tougher one) to solve the problem .

  • Implement the algorithm in C, C++, Pascal or Java .

  • Finally, if you are convinced of its correctness, upload your code to have it judged.


The judging is automated (they use benchmark input and output files), so you can typically expect a response within a few seconds. After all the theory above (we have had enough of it :P) , lets try and solve a problem at the uva site.

Getting started : A step-by-step approach

Lets get started with an easy question  :) . I have selected the  problem at the uva  called Back to High School Physics . It is indeed an easy problem . Go through the question , use sample input and sample output section to see what they really need . Once you get a feeling of what to do , try finding out the formula (the so called "algorithm" for this problem) . Think hard if you dont get it  ,

  • visit this link .

  • click on volume 100 (since it is question no 10071 on the uva site)

  • Scroll down and you will get a hint to the problem .


Alternatively ,  search google for  10071 - Back to High School Physics . Click on a link from the algorithmist's site . You will reach here . You could find some clues here too . But please try yourself before you go onto look at the hints using one of the two methods  because thats the whole motive behind starting with uva .  By now you are ready to dive into your compiler and code ,so do it !!! . You may also use ideone .  Its a really good place to try different input/ outputs and check if your code is error-free . Let me post the solution for this question to show you a sample solution :

[sourcecode language="cpp"]

#include<stdio.h>
int main()
{

long int v,t,s;

while(scanf("%ld%ld",&v,&t)==2){

s=v*t*2;

printf("%d\n",s);

}
return 0;
}
[/sourcecode]

Log in to the uva website  . Go to Quick submit on the left . Enter question number on uva site (10007 here) , choose a language (click on C for above sample code) , copy-paste your code here (you may browse it as well :) ) and submit your code Congratulations !!!! you have now submitted a solution at the uva site (if you get AC- accepted) . You can check the status of your submission by selecting the “My Submissions” link on the left side of the page. The “Verdict” heading will tell you if it was solved or if there was a problem (e.g. wrong answer, ran too long, crashed, too much memory was used, compile error, etc).

Now go ahead and solve some more problems  !!!

Next Problem to Solve :

As there are large number of problems to be solved, you have to select problems. The best way according to me is  Felix Halim’s website. Just punch in your username and see the miracle. Bookmark the page, at least that’s what I did :D .

Use Felix Halim for figuring out what problem will be easiest to find:


image


Or you can also get Topic wise problems:


image


Another word of advice, the solutions for UVA are available abundantly on the net. Please do not copy, as this is not a competition!





  • First try to solve a problem by your self.


  • If you keep on getting WA’s, Try UVA Toolkit to check for critical input.


  • If you still get WA’s, try reading on UVA forum and you might get critical test cases there!


  • Still a WA then read a solution, but definitely write your own code!


AC’s are heavenly, work for them! Have fun…Enjoy coding!!!


If you use google-chrome :


Sometimes , The site wont open and it will  show a redirect loop. It is solved by removing the cookie onlinejudge.org. It can be removed in the following way. Open options->under the hood:


image


Click on “content settings”, and in “cookies” sections click on “all cookies and site data”.


image
now search for onlinejudge.org cookie and delete it..Tada problem solved!( P.S. the screenshots are from this page ).

17 comments:

  1. gud one dr... bht logo ko help milega.. :-)
    baba ki jai ho....

    ReplyDelete
  2. nice blog .....
    great Work!!!
    W8ing for another "Getting Started With Codeforces".... :P

    ReplyDelete
  3. ty so much sir ... hope people start coding now !!! Did all this specially for juniors ..

    ReplyDelete
  4. thanks for the compliment !!! and yes m also in learning mode at codeforces , will try and do it soon :)

    ReplyDelete
  5. Great Effort. Keep it up :)

    ReplyDelete
  6. thanks abhishek !!! you guys have inspired me to code .... m spreading it among odrs now :)

    ReplyDelete
  7. thank you so much bhaiya .... jo sikha hai ..share kar rahe hain :)

    ReplyDelete
  8. thanku bhaiya....it helps alot....

    ReplyDelete
  9. My pleasure :) Let me know if you people want me to discuss any other topic !!!

    ReplyDelete
  10. I removed the cookie but I am still not able to access the site :(

    ReplyDelete
  11. Why dont you try out in firefox ;)

    ReplyDelete
  12. doesn't work in firefox either.. does the site work for you?

    ReplyDelete