UVA Sample
Now that you have had plenty of time to try it out for yourselves (although I haven't had
a full set of people turning anything in yet, so I'm assuming that everyone is waiting until
they've solved all 800 problems, and they're going to surprise me with them all at once, tomorrow afternoon),
here is a sample of a solution that is accepted as correct by the UVA site. If you haven't been able to get one submitted,
a quick comparison to see what you'd missed should do the trick.
Depending on what kind of computer you have access to, the way you send programs to the automatic judge will
vary. If you have unix (including linux and bsd) it is very easy: assuming that your program in in a file
called "prob100.cpp", you just type this command mail judge@uva.es <prob100.cpp.
If you are using Windows, it is a little more complex. My researches have shown that Microsoft's
Mailer is Completely Incapable of sending a message correctly without adding its own rubbish to the
text. I have not successfully submitted a program using Microsquit's products. Instead I have had to use Netscape,
and suggest that you do the same. If any of you have succeeded with Microsoft, please let me know what you did.
The first time you use Netscape to send mail, it will ask you about your mail servers. Whichever ones you
use normally for email can also be used with netscape. IF (and only if) you have trouble with submissions getting through,
here is a little trick you can use: set the outgoing (SMTP) server to mail-server.uva.es. That way
it will connect directly to the Spanish site and deliver your mail by hand. Of course, this only works for
sending mail to the on-line judge.
To submit programs with Netscape, you must select "Messenger" under the "Communicator" menu, and the first time you use
it, you must
then select "Preferences..." under the "Edit" menu, go to the "Mail & Newsgroups" - "Messages" sub-option,
and set the field marked "Wrap outgoing plain-text messages at" to a VERY BIG number; I use 999. If you don't do this, it
will cut your program's lines in half at bad places and insert errors. Then press "OK" and you should be ready to
submit something at last.
To submit a program, press the big "New Msg" icon-button, set the "To:" field to judge@uva.es, and
Copy and Paste your program into the message area. DO NOT add it as an attachment.
I'm sorry the procedure is so complicated; there is no reason why it should be like this, and indeed. under unix it isn't.
Complain to Microsoft.
/* @JUDGE_ID: 9999ZZ 100 C++ "Howdy!" */
#include <stdio.h>
#include <stdlib.h>
// This first function computes the length of the cycle
// beginning from one particular value (n). The main program
// uses this function in a loop to get the longest cycle
// length within a range
int cycle_length(int n)
{ int len = 1;
while (n != 1) // keep repeating until n reaches 1:
{ if (n%2 == 1) // if n is odd
n = 3*n + 1; // n becomes 3n+1
else // otherwise, if n is even
n = n/2; // n becomes n/2
len += 1; } // and keep count of the number of loops
return len; }
// The main function just keeps reading pairsof numbers until there
// are none left.
// It puts the pair of numbers in the right order (if someone asked
// you how many numbers there are between 20 and 10, you would
// probably not say "none". Your program must be equally flexible)
void main(void)
{ int n, k, a, b, v1, v2, max, len;
while (1) // don't know how many input pairs,
// so keep on going indefinitely
{ k=scanf("%d %d", &a, &b); // scanf attempts to read 2 ints
// k is set to the number actually read
if (k!=2) break; // if k!=2 we must have been at the end
// of the inputs, so stop.
v1 = a;
v2 = b;
if (v1>v2)
{ v1 = b; // after this, v1 and v2 are the two inputs
v2 = a; } // and it is guaranteed that v1<=v2
max=0; // max records the longest cycle seen so far
for (n=v1; n<=v2; n+=1) // loop covers whole range between v1 and v2
{ len = cycle_length(n);
if (len>max) // if this cycle is longer than the longest
{ max = len; } } // so far, keep it instead.
// finally print the answer
printf("%d %d %d\n", a, b, max); } }