#include <stdio.h>
int const MAX =100;
int array[MAX], i;
void main( void )
{
for (i = 0; i < =100;i++)
{
if (array[i] = =100)
{
array[i] = –10000;
––––––
––––––
––––––
#include <stdio.h>
float store[100];
void main( void )
{
int j;
float temp;
for ( j = 0; j < 100; j++)
{
scanf( "%f", &temp);
store[ j] = temp;
}
}
}
}
}
In this example, you have allocated a 100 element array. Your program attempts to access array element 100, which is out of the range
[0..99], because of an error in the for loop statement. It will instead
access the address of counter variable i. Because the value array[100]
is set to –10000, the counter value will be set to –10000, so your loop
will take a much longer time to terminate and may not even complete
at all. So, the judge will give you the message “Time limit exceeded”
even though it actually is a memory allocation error.
Test the Program with Multiple Datasets
There is always a sample input and output provided with each contest
question. Inexperienced contestants get excited when one of their programs matches the sample output for the corresponding input, and
they think that the problem has been solved. So they submit the problem for judgment without further testing and, in many cases, find they •
have the wrong answer. Testing only one set of data does not check if
the variables of the program are properly initialized because by default
all global variables have the value zero (integers = 0, chars = '\x0',
floats = 0.0 and pointers = NULL). Even if you use multiple datasets
the error may remain untraced if the input datasets are all the same
size, in some cases descending in size or ascending in size. So, the size
of the dataset sequence should be random. It is always a good idea to
write a separate function for initialization. •
•
•
Take the Input of Floats in Arrays
Consider the following program segment:
#include <stdio.h>
float store[100];
void main( void ) {
int j;
for ( j = 0; j < 100; j++)
scanf( "%f", &store[ j]);
Mark Dettinger’s Suggestions on Geometric Problems
Mark Dettinger was the coach for the team from the University of
Ulm. He suggested to me that sometimes it is a good idea to avoid geometric problems unless one has prewritten routines. The routines that
can be useful are:
• Line intersection.
• Line segment intersection.
• Line and line segment intersection.
• Convex hull.
• If a point is within a polygon.
• From a large number of points what is the number of maximum
points on a single line.
• Closest pair problem. Given a set of points you have to find out the
closest two points between them.
Try to learn how to use C’s built-in qsort function to sort integers
and records.
• Area of a polygon (convex or concave).
• Center-of-gravity of a polygon (convex or concave).
• Minimal circle, a circle with the minimum radius that can include
the coordinates for a given number of points.
Minimal sphere.
Whether a rectangle fits in another rectangle even with rotation.
Identify where two circles intersect. If they do not, determine
whether one circle is inside another or if they are far away.
• Line clipping algorithms against a rectangle, circle, or ellipse.
}
When this program is run, many C/C++ compilers show the error
“Floating point format not linked.” To get rid of this type of error, just
change it to take the input into a normal floating point variable then
assign that variable to the array, as follows:
Judging the Judge!
Judges often omit information. For example, judges in my country give
the error “Time limit exceeded” but never say what the time limit is.
In Valladolid, often the input size is not specified (e.g., problem 497-
Strategic defense initiative).
Suppose that the maximum number of inputs is not given. This is
often vital information because if the number is small, you can use
backtracking, and if it is large, you have to use techniques like dynamic
programming or backtracking with memorization. In problem 497, the