#include
/* ski chair lift program */
int main(int argc, char **argv)
{
int N, meChair, otherChair;
double T;
double timeToTop;
double invspeed;
double numChairs;
scanf ("%d %lf\n", &N, &T);
if ((18 > N) || (N>300) || (N%2 !=0))
{
printf("Bad Input on N\n");
exit(-1);
}
if ((200 > T) || (T>999.9))
{
printf("Bad Input on T %f\n", T);
exit(-1);
}
printf("Program 1 by team X\n");
printf ("N = %3d, T = %3.1f\n",N, T);
invspeed = (2.0 * T)/(N-1); /* time to the top is T. In that time,
the 1st chair has moved k*(N-1)/2 units
of distance, where k is the numer of
meters between chairs. D(m) = V(m/s)*T(s)
so V = D/T v = m/s. We have 1/V */
while ((scanf("%d %d\n", &meChair, &otherChair) != EOF))
{
if ((meChair > N) || (otherChair > N))
{
printf("Bad chair locations \n");
exit(-1);
}
if (meChair > otherChair)
{
numChairs = (double) (meChair - otherChair -.5)/2;
/* Number of chairs determined by half the length of
* the difference, between chair numbers allowing for
* half a distance of length to be around the pulley
*/
timeToTop = (double) numChairs*invspeed; /* T = D/V or D*(1/V) */
}
else
{
numChairs = (double) (N + meChair - otherChair -.5)/2;
/* If wrapped around, you need to add N to this number so
* it's a proper modulus operation. Draw the picture.
* for example if I'm at the bottom in chair 1, chair 2 is
* the next chair I meet. I'm actually (N-1)/2 chairs from
* the top. (N + 1 - 2)/2
*/
timeToTop = (double) numChairs*invspeed;
}
printf("Chair %3d meets chair %3d, remaining time = %5.1f\n",
meChair, otherChair,timeToTop);
}
printf("End of program 1 by team X\n"); /* This line extremely important */
exit (0);
}