Eighth episode, physical training timelimit:1000ms memorylimit:128mb64-bit integer IO format:%i64dProblem Description
SmallAand smallCBashansheshui,finally came to the agents to gather the city , they two in the vicinity to find a hotel to live under. At this time, distance from the agents gathering more and more close , it is time to a wave of physical training, in case of danger, run too slow , was caught , GG ...
SoSmallAand SmallCtogether came to the hotel near the stadium of the ring playground running, at first, they agreed to two people,At first they were two people from the same point of,running in the opposite direction, each time two people meet each other, the firstkyou need to rest when you meetkseconds,then continue running in the opposite direction at the original speed. Now, tell you the length of the playground is L, small Aand SmallCthe speed of running isVaand theVc. That's when the problem comes and asks you to go throughkseconds, output the number of times they met,
due to the limited physical strength of two people, they agreed to meet each other in two . 10000 I won't run away again. ,
Input
There are several sets of test cases,
For each set of test cases, the first line enters three positive integers, L,va and Vc (1<=va,vc<=10,1<=l<=1000).
The second line enters a Q (q<=10000), which indicates the number of queries.
Next there is Q line, each line input a positive integer k (1<=k=10^9), indicating that after k seconds, they met how many times,
Output
For each query time, output the number of times they met,
Sampleinput
2 1 180131020215000000511768840
Sampleoutput
012456316110000
Idea: This problem is actually a math problem, or a physics problem. The time they need to run a lap is L/(VA+VC), and then as the number of encounters increases, the rest time will increase, which is actually a arithmetic progression, with 1 headed, 1 for the tolerance of arithmetic progression. And so we can conclude that the time required to meet the nth time is(N*L)/(va+vc)+N*(N+1)/2.0-N,
因为N次相遇的时候,他们还没有休息,所以在式子的最后要减一个N。因为题目所需的时间为1000MS,如果我们用for循环一次一次的去试,肯定会超时,所以我们就需要用到二分。
这时候就比较简单了,这时候就要注意一点也就是要转化为浮点运算,鉴于个人因为没有转化为浮点运算,WA了好几次233.转化为浮点运算,然后跟K比较大小就可以了
IntFind(){int L=0R=10010;int mid;While(l<r){Mid=(l+r)/2;If((1.0*mid*l)/(VA+vc) +mid*+1 /2.0-mid>k)//nth meeting time compared to the required K of the topic R=midelse l=mid+1 return r;
本人AC的内存与时间以及代码长度:1856KB,528MS,359
Level 16, first week of winter vacation homework D problem