Bus

Question

Solution

Idea

This is another math problem. A tricky point is the in this question, there is a chance that "half" of a passenger (horrible 😱) may get off the bus. But as stated in the question, there is no passenger hurt. So, it is safe for you to start from the last stop.

Code

https://github.com/mendax1234/Coding-Problems/blob/main/kattis/bus/bus.c
#include <stdio.h>

int main()
{
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i += 1)
  {
    double ans = 0;
    int temp;
    scanf("%d\n", &temp);
    for (int k = 0; k < temp; k += 1)
    {
      ans += 0.5;
      ans *= 2;
    }
    printf("%d\n", (int)ans);
  }
}

Last updated