首页 > ACM题库 > HDU-杭电 > HDU 3044- Dog and dog[解题报告]HOJ
2014
02-27

HDU 3044- Dog and dog[解题报告]HOJ

Dog and dog

问题描述 :

Nowadays, Xiaoyang thinks of a simple problem. The problem is derive from primary school: Two men get close with the same speed v1, there is a dog run between them with speed v2. It is easy to answer the question that how long dog has run (D) before they meet. Since it is so easy, he want to change this problem. Two men can see each other within 10 meters, if their distance less than 10 meters, then they stop. The dog can run at most L2 meters. At first, two man’s distance is L1 meters, their speeds are changed. The left man’s speed becomes  Number game and the right man’s speed becomes  Number game . The dog’s speed also changed to  Number game

输入:

the first line N, then N lines follows
each line has 4 parameters L1, L2, V1, V2;

0<=L1,L2<=100,0<v1,v2<=100

输出:

the first line N, then N lines follows
each line has 4 parameters L1, L2, V1, V2;

0<=L1,L2<=100,0<v1,v2<=100

样例输入:

2
9 1 2 3 
47 11 25 9

样例输出:

0
11

http://acm.hdu.edu.cn/showproblem.php?pid=3044

当初我看到它的公式这么复杂,所以就一下子忽略这题了,想起来还真有点后悔。

好的,我翻译一下这一的意思吧!其实就是告诉你两个人和一条狗各时刻的瞬时速度,让你求出两人相遇的时候狗跑了多长的距离。当然,这里的相遇只需要两人相距10m以内。这个看上去很复杂的积分题如果在你做的时候注意一些细节,那么你就可以瞬间秒杀它了。
 
我的做法是在积分的过程中,把sin(sin2t)sin(cos2t)看做一个整体,假设是间接时间x(因为两者是一一对应的)。那么,此时的两个人对其速度和的积分就只是积v=v1sin(1)/x,最后在两人相遇前,所用的间接时间x=e(l1-10)/t。
同理,对狗的速度的积分将变成v=v2cos(1)*1.55741/x,最后积得间接时间x内狗跑的距离s=v2cos(1)*1.55741*ln x。
整理可得,狗在两人相遇前最多能跑的距离为s=v2cos(1)*1.55741*(l1-10)/v1/sin1。然后就是比较数据给出狗跑的最长距离就可以得出答案了。
 
 
View Code
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 
 6 int main()
 7 {
 8     int T;
 9     double s, l1, l2, v1, v2;
10 
11     scanf("%d", &T);
12     while(T--)
13     {
14         scanf("%lf%lf%lf%lf", &l1, &l2, &v1, &v2);
15         s=cos(1)*1.55741*v2*(l1-10)/v1/sin(1);
16         if(s<0)printf("0\n");
17         else if(s>l2)printf("%.0lf\n", l2);
18         else printf("%.0lf\n", s);
19     }
20     return 0;
21 }
 
written by Lyon

参考:http://www.cnblogs.com/LyonLys/archive/2012/03/16/hdu_3044_Lyon.html


  1. Often We don’t set up on weblogs, but I would like to condition that this established up really forced me individually to do this! considerably outstanding publish

  2. 换句话说,A[k/2-1]不可能大于两数组合并之后的第k小值,所以我们可以将其抛弃。
    应该是,不可能小于合并后的第K小值吧

  3. 为什么for循环找到的i一定是素数叻,而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak,而你每次取余都用的是原来的m,也就是n