hdu-5761 Rower Bo(数学)

题目链接:

Rower Bo

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 131072/131072 K (Java/Others)

Problem Description
There is a river on the Cartesian coordinate system,the river is flowing along the x-axis direction.

Rower Bo is placed at (0,a) at first.He wants to get to origin (0,0) by boat.Boat speed relative to water is v1,and the speed of the water flow is v2.He will adjust the direction of v1 to origin all the time.

Your task is to calculate how much time he will use to get to origin.Your answer should be rounded to four decimal places.

If he can't arrive origin anyway,print"Infinity"(without quotation marks).
 

 

Input
There are several test cases. (no more than 1000)

For each test case,there is only one line containing three integers a,v1,v2.

0a1000v1,v2,100a,v1,v2 are integers
 

 

Output
For each test case,print a string or a real number.

If the absolute error between your answer and the standard answer is no more than 104, your solution will be accepted.
 

 

Sample Input
 
2 3 3
2 4 3
 

 

Sample Output
 
Infinity
1.1428571429
 
题意:
 
给小船的初始位置,水的流速,小船相对于水的速度;现在小船每刻的方向都朝向原点,问小船到达原点的用时是多少;
 
思路:
 
我太笨了,当时比赛的时候就不会做;后来看的题解;
 
http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-3-solutions-by-%E7%BB%8D%E5%85%B4%E4%B8%80%E4%B8%AD/
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>

using namespace std;

#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));

typedef  long long LL;

template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}

const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e6+10;
const int maxn=500+10;
const double eps=1e-8;


int main()
{       
        double a,v1,v2;
        while(scanf("%lf%lf%lf",&a,&v1,&v2)!=EOF)
        {

            if(v1<=v2)
            {
                if(v1<=v2&&a>0)printf("Infinity\n");
                else printf("0\n");
            }
            else 
            {
                printf("%.6lf\n",1.0*v1*a/(v1*v1-v2*v2));
            }
        }
        
        return 0;
}

  

posted @ 2016-07-26 21:35  LittlePointer  阅读(254)  评论(0编辑  收藏  举报