maximum possible number of missiles to intercept is not given.
Suppose that the loop for( j = 0; j < I *100000000; j++) takes one
second to run for the judge, and an unknown N is the number of
inputs given by the online judge. Send the following program with your
code. Place it just after you have read the value of N.
for (I = 1;I < = 20;I++)
{
if ( I *1000 > = N)
{
for( j = 0; j < I *100000000; j++);
}
}
From the runtime of the program you will know the number of
input N. Using this method you can also determine how fast the
judge’s computer is compared with yours and thus find out the approximate time limit for any problem on your computer. Most of the live
contests have a practice session prior to the contest. On this day you
should try to determine the speed of the judge computer by sending
programs consisting of many loops and nested loops.
Did you know that there was a mistake in a problem of the World
Final 2000? The culprit problem was Problem F. The problem specification said that the input graph would be complete but not all inputs
by the judge were complete graphs. At least one of the teams sent a
program that checked if the input graph was complete. If the input
graph was incomplete, then their program entered an infinite loop. So,
the response from the judge was “Time limit exceeded.” From this
response they were able to know that some of the input graphs were
not complete and solved the problem accordingly.
Use Double Instead of Float
It is always a good idea to use double instead of float because double
gives higher precision and range. Always remember that there is also a
data type called a long double. In Unix/Linux C/C++, there is also a
long long integer. Sometimes it is specified in the problem statement
to use float type. In those cases, use floats.
Advanced Use of printf and scanf
Those who have forgotten the advanced use of printf and scanf,
recall the following examples:
scanf( "%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]", &line);
//line is a string
abc
def
and the following program is executed to take input from the file:
char input[100], ch;
void main( void )
{
freopen( "input.txt", "rb", stdin);
scanf( "%s", &input);
scanf( "%c", &ch);
}
What will be the value of input and ch?
The following is a slight modification to the code:
char input[100], ch;
void main( void )
{
freopen( "input.txt", "rb", stdin);
scanf( "%s\n", &input);
scanf( "%c", &ch);
}
What will be their value now? The value of ch will be “\n” for the first
code and “d” for the second code.
Memorize the Value of Pi
You should always try to remember the value of pi as far as possible,
3.1415926535897932384626433832795, certainly the part in italics.
The judges may not give the value in the question, and if you use values like 22/7 or 3.1416 or 3.142857, then it is very likely that some of
the critical judge inputs will cause you to get the wrong answer. You
can also get the value of pi as a compiler-defined constant or from the
following code: Pi = 2*acos(0).
Problems with Equality of Floating Point (Double or
Float) Numbers
You cannot always check the equality of floating point numbers with
the = = operator in C/C++. Logically their values may be same, but
due to precision limit and rounding errors they may differ by some
small amount and may be incorrectly deemed unequal by your program. So, to check the equality of two floating point numbers a and b,
you may use codes like:
This scanf function takes only uppercase letters as input to line and
any other characters other than A..Z terminates the string. Similarly
the following scanf will behave like gets:
scanf( "%[^\n]", line); //line is a string
if (fabs(a– b) <ERROR) printf( "They are equal\n" );
Here, ERROR is a very small floating-point value like 1e – 15. Actually,
1e – 15 is the default value that the judge solution writers normally use. This
value may change if the precision is specified in the problem statement.
Learn the default terminating characters for scanf. Try to read all the advanced features of scanf and printf. This will help you in the long run.
Using New Line with scanf
The Cunning Judges
Judges always try to make easy problem statements longer to make
them look harder and the difficult problem statements shorter to make
them look easy. For example, a problem statement can be “Find the
common area of two polygons”—the statement is simple, but the solu-