1999 LSU Computer Science High School Programming Contest
Novice Problem 6
Orange Barrels

Return to the Top of Page, First Page, or Novice Problem Set.


Problem Statement

When highways are being worked on, the repair crews use Orange Barrels to tell you when you can/should move over (lanes are closed or they re-open). The Larry-Darrel-Darrel Construction Company always puts 13 Orange Barrels before a lane ends (13 per each lane). They always put 9 Orange Barrels when you regain a lane. You are to read in a series of lane widths and determine how many barrels you see while traveling that stretch of road and how many times the number of lanes changes.

Sample Input Data:

3 
2 
4 
3
0
4 
5 
2 
3 
4 
5 
6 
3 
4 
5
0
-1

NOTE: Each highway will end when you encounter a zero (0). You will stop processing when you encounter a negative one (-1).

Sample Output:

This highway changed width 3 times and we saw 44 Orange Barrels.
This highway changed width 9 times and we saw 141 Orange Barrels.

NOTE: Do not worry about the formatting of numeric output (leading/trailing spaces around numbers are acceptable).

Explanation of Calculation:

The highway 3 2 4 3 would be calculated as follows:

    The highway starts at 3 lanes wide and you have seen no barrels
  1. The highway narrows by 1 lane to 2 lanes wide and you see 13 barrels for a total of 13 barrels
  2. The highway widens by 2 lanes to 4 lanes wide and you see 18 barrels for a total of 31 barrels
  3. The highway narrows by 1 lane to 3 lanes wide and you see 13 barrels for a total of 44 barrels



Return to the Top of Page, First Page, or Novice Problem Set.


Clarifications:







Return to the Top of Page, First Page, or Novice Problem Set.


Source Code for a Solution to this Problem

// preprocessor directives
#include <stdio.h>


int main(void)
{
   int lanes;     /* width of current highway */
   int past;      /* previous width of highway */
   int count;     /* number of times that highway width changes */
   int barrels;   /* number of barrels that have been seen */

   scanf("%d",&lanes);  /* priming read */

   while(lanes != -1)   /* while more highways to process */
   {
     barrels = 0; count = 0;  /* initialize variables for this highway */
     past = lanes;         /* set past so count won't get incremented */
     
     while (lanes != 0)  /* while more lanes in this highway */
     {
       if (lanes != past)   /* have we have a change in number of lanes */
        {
          if (lanes > past)
           barrels += 9 * (lanes - past);   /* highway got wider */
          else
           barrels += 13 * (past - lanes);  /* highway got narrower */

           count++;                         /* highway width changed */

           past = lanes;                    /* remember current width */
        }
       scanf("%d",&lanes);                  /* get new lane-width */
     } /* END of while more lanes in this highway */ 

    printf("This highway changed width %d times and we saw %d Orange Barrels.\n", count, barrels);
 
    scanf("%d",&lanes);   /* new highway ? */

   } 

   return 0;

}//main

Return to the Top of Page, First Page, or Novice Problem Set.


Sample Input

3 
2 
4 
3 
0
4 
5 
2 
3 
4 
5 
6 
3 
4 
5 
0
-1

Return to the Top of Page, First Page, or Novice Problem Set.


Sample Output

This highway changed width 3 times and we saw 44 Orange Barrels.
This highway changed width 9 times and we saw 141 Orange Barrels.

Return to the Top of Page, First Page, or Novice Problem Set.


Judge Data Set 1 - Input

3 
2 
4 
3 
0
4 
5 
2 
3 
4 
5 
6 
3 
4 
5 
0
4 
2 
3 
4 
2 
3 
4
5 
2 
0
8
6
4
5
4
2
5
0
3
3
5
6
7
2
1
4
0
-1
2 
3 
4 
2 
4 
3 
0

Return to the Top of Page, First Page, or Novice Problem Set.


Judge Data Set 1 - Output

This highway changed width 3 times and we saw 44 Orange Barrels.
This highway changed width 9 times and we saw 141 Orange Barrels.
This highway changed width 8 times and we saw 136 Orange Barrels.
This highway changed width 6 times and we saw 127 Orange Barrels.
This highway changed width 6 times and we saw 141 Orange Barrels.

Return to the Top of Page, First Page, or Novice Problem Set.


Judge Data Set 2 - Input

12
6
4
7
6
9
8
10
0
1
1
0
8
8
8
9
0
9
8
7
6
5
4
3
2
1
2
3
4
5
6
7
8
9
0
9
2
8
3
7
1
6
4
6
0
-1

Return to the Top of Page, First Page, or Novice Problem Set.


Judge Data Set 2 - Output

This highway changed width 7 times and we saw 202 Orange Barrels.
This highway changed width 0 times and we saw 0 Orange Barrels.
This highway changed width 1 times and we saw 9 Orange Barrels.
This highway changed width 16 times and we saw 176 Orange Barrels.
This highway changed width 8 times and we saw 413 Orange Barrels.

Return to the Top of Page, First Page, or Novice Problem Set.



The statements and opinions included in these pages are those of the LSU High School Programming Contest Staff only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999 LSU High School Programming Contest

Return to the LSU High School Programming Contest Homepage