Topic Link: UVA 12230-crossing Rivers
There is a person to go to the company every day to work. Every time it passes through N rivers. The distance between the home and the company is D. By default, the speed of the land is 1, giving information about the N River. Contains the starting coordinates p, width l, and the speed of the boat.
The boat will be back and forth on both sides of the river. People reach the riverbank is. The position of the ship is random (including direction). Ask people to reach the desired time that the company needs.
Problem-solving idea: The time on land is fixed, and it is only necessary to calculate the time of each river separately. As people arrive at the shore, the position of the ship is random, so the waiting time [0,2l/v], the period is equal probability, so the time of a river is extremely(0+ 2? L v ) 2 +l v = 2? L v
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;intMain () {intCAS =1;intNDoubleD, P, L, V; while(scanf("%D%LF", &n, &d) = =2&& (N | | D)) { for(inti =0; i < N; i++) {scanf("%LF%LF%LF", &p, &l, &v); D = D-l +2* L/V; }printf("Case%d:%.3lf\n\n", cas++, D); }return 0;}
UVA 12230-crossing Rivers (probability)