WHOJ 1609 - Han Move【细心】

Problem 1609 - Han Move
Time Limit: 1000MS    Memory Limit: 65536KB   
Total Submit: 618   Accepted: 160   Special Judge: No
Description
Cyy and Fzz are Han Move lovers. One day, they gather together to run. They choose a circular track whose length is L m. Cyy’s speed is A m/s and Fzz’s speed is B m/s. They may choose the direction separately, i.e. they may start with the same direction or different direction. As they’re crazy, they’ll run infinitely. Gatevin, their friend, wonders the possibility of their distance is less than D m. The distance is defined as the distance on the track. The possibility is defined as the ratio between the sum of time satisfying the condition and the total time.
Input
The input file consists of multiple test cases ( around 1000000 ).
Each test case consists of 5 integers L, A, B, D, Dir in a line. The meanings of L, A, B, D are as described above. Dir means whether they are in the same direction. Dir = 1 means they are in the same direction, while Dir = 0 means they are in the opposite direction. ( 1 <= L, A, B, D <= 32768, 0 <= Dir <= 1 )
Output
For each test case, output the possibility rounded to 6 demical places in a line.
Sample Input
1200 200 400 300 0
1200 200 400 300 1
Sample Output
0.500000
0.500000
Hint

 Please pay attention to the speed of I/O.

题意:两个同学同时在一个出发点出发,有可能同向,有可能反向,可以计算相对速度,如果反向,一个人不动,另一个人的速度为两人的速度之和;如果同向,一个人不动,另一个人的速度为两人的速度之差,需要注意的是保留六位小数。

AC-code:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#define abs(a) a>0?a:-a
using namespace std;
int main()
{
	int a,b,c,d,e;
	while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)!=EOF)
	{
		int v;
		if(e==0)
		{
			v=b+c;
		}
		else
		{
			v=abs(b-c);
		}
		if(v==0)
		{
			printf("1.000000\n");
			continue;
		}
		double p=2.0*d/a;
		if(p>1)
			 printf("1.000000\n");
		else
			printf("%lf\n",2.0*d/a);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值