I have problem I'm sitting with.
For example, suppose someone runs in straight lines and at constant speed between the positions on the left side of Table 1. The time they reach each position is shown next to the position. They stopped running at time 11. If the GPS records a position every 2 units of time, its readings would be the records on the right side of Table 1.
input: The input consists of a single test case. The first line contains two integers n(2 <= n <= 100) and t(1 <= t <= 100), where n is the total number of positions on the running path, and t is the recording time interval of the GPS (in seconds).
The next n lines contain three integers per line. The i-th line has three integers Xi, yi (-10^6 <= xi, yi <=10^6), and ti (0 <= ti <= 10^6), giving the coordinates of the i-th position on the running path and the time (in seconds) that position is reached. The values of ti’s are strictly increasing. The first and last positions are the start and end of the run. Thus, t1 is always zero.
Given a sequence of positions and times for a running path, as well as the GPS recording time interval , calculate the percentage of the total run distance that is lost by the GPS. Your computations should assume that the runner goes at a constant speed in a straight line between consecutive positions.
My code can calculate the correct output out of the data from the picture but some of the test's will fail. The thing is that I dont now how the tests looks like. So I only know how the indata for the first test looks like.
int main(int arg, char* argv[]) {
int n, t;
int time, new_time, pos_x, pos_y, new_pos_x, new_pos_y;
double run_distance = 0, gps_distance = 0;
int gps_pos_x = 0, gps_pos_y = 0, gps_new_pos_x, gps_new_pos_y;
int gps_time = 0;
if(scanf("%d %d", &n, &t) != 2){
return 0;
}
if(scanf("%d %d %d", &pos_x, &pos_y, &time) != 3){
return 0;
}
for (int i = 0; i < n - 1; i++)
{
if(scanf("%d %d %d", &new_pos_x, &new_pos_y, &new_time) != 3){
return 0;
}
//Calculate run distance
run_distance += sqrt((new_pos_x - pos_x)*(new_pos_x - pos_x) + (new_pos_y - pos_y)*(new_pos_y - pos_y));
//Gps time
gps_time += t;
// Difference between new position X and old position X
int diff = new_pos_x - pos_x;
int pos;
// Difference between gps time and time of old position
int time_diff = gps_time - time;
// Calculate new gps position
pos = diff/(new_time - time) * time_diff + pos_x;
// Save new position
gps_new_pos_x = pos;
// Difference between new position Y and old position Y
diff = new_pos_y - pos_y;
// Calculate new gps position
pos = diff/(new_time - time) * time_diff + pos_y;
// Save new gps position
gps_new_pos_y = pos;
//printf("%d, %d\n", gps_new_pos_x, gps_new_pos_y);
//Calculate gps distance
gps_distance += sqrt((gps_new_pos_x - gps_pos_x)*(gps_new_pos_x - gps_pos_x) + (gps_new_pos_y - gps_pos_y)*(gps_new_pos_y - gps_pos_y));
pos_x = new_pos_x;
pos_y = new_pos_y;
time = new_time;
gps_pos_x = gps_new_pos_x;
gps_pos_y = gps_new_pos_y;
}
gps_distance += sqrt((pos_x - gps_pos_x)*(pos_x - gps_pos_x) + (pos_y - gps_pos_y)*(pos_y - gps_pos_y));
//float diffirence = run_distance - gps_distance;
float value = (run_distance - gps_distance)/run_distance * 100;
printf("%.15f\n", value);
return 0;
}

