3932 - Poker and Walk

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

One day, Moat invited TeStatic to play poker at teaching building 9, and TeStatic was in teaching building 7 at that time.

TeStatic has special walking habit. He will stop T0 seconds after every T seconds' walking. We know that the distance between teaching building 7 and teaching building 9 is L meters, and the speed of TeStatic when he walks is V meters pre second.

So, how much time that Moat had to wait?

题目输入

In the first line of input file, there will be a positive integer T , indicating the number of data set.

Each data set contains a line with 4 integers V,T,T0,L . The meaning of them has been stated in Problem Description.

We guarantee that: <br />

<p class="MathJax_Display">
	<span class="MathJax" id="MathJax-Element-7-Frame"><span class="mrow" id="MathJax-Span-30">1≤V≤10</span></span> 
</p>
<p class="MathJax_Display">
	<span class="MathJax"><span class="mrow"><span class="mo" id="MathJax-Span-36"></span>1≤T≤100</span></span> 
</p>
<p class="MathJax_Display">
	<span class="MathJax"><span class="mrow"><span class="mo" id="MathJax-Span-42"></span>1≤T<span>0</span>≤100</span></span> 
</p>
<p class="MathJax_Display">
	<span class="MathJax"><span class="mrow"><span class="mo" id="MathJax-Span-50"></span>1≤L≤1000</span></span> 
</p>

题目输出

For each data set of input, print the time asked in second (rounded to 3 decimal places) in a line.

输入/输出样例

输入格式

2
1 3 1 10
1 4 2 10

输出格式

13.000
14.000

C++解答

#include <stdio.h>

int main()
{
  int casc;
  scanf("%d", &casc);
  for (int casi = 1; casi <= casc; casi++) {
    int v, t, t0, l;
    scanf("%d %d %d %d", &v, &t, &t0, &l);
    int s = v * t;
    double res = l / s * (t + t0);
    if (l % s == 0)
      res -= t0;
    else res += 1.0 * (l % s) / v;
    printf("%.3f\n", res);
  }
  return 0;
}