UESTC 1171 Ants Run!

Ants Run!

Time Limit: 1000 ms Memory Limit: 65535 kB 

 

 

Description

Professor Yang likes to play with ants when he is free. What? Are you asking why he plays with ants instead of others? Ah, because ant is the only non-plant living thing which can be found in Qingshuihe Campus of UESTC apart from human beings.
This time, Professor Yang caught several ants after finishing his lecture for freshmen. At the beginning of the game, he puts N ants around a plate and numbers them in clockwise order. The ants are so obedient that they run clockwise under the guide of Professor Yang on the boundary of the plate which is a circle. When one ant catches up with its previous ant, the game is over. Knowing the speed of ants, Professor Yang wants you to help him to adjust the distance between adjacent ants to make the game last longer. 

Input

The first line of the input is T (no more than 10000), which stands for the number of test cases you need to solve. 
Each test case begins with “N R”(without quotes) representing the number of ants participating the game is N and the radius of the circle is R cm. The next line lists N integers and the i-th number is the speed (cm/s) of the i-th ant in clockwise direction. All numbers are positive integer not larger than 20.

Output

If the game can last forever, print “Inf” in a single line, otherwise please output the longest time in seconds each game can last, which should be printed accurately rounded to three decimals.

Sample Input

2
3 1
1 1 1
3 1
3 2 1

Sample Output

Inf
3.142

Source

The 8th UESTC Programming Contest Preliminary

 

 

 

解题思路:
一群蚂蚁围成一圈以各自的速度沿顺时针方向跑,求大家互不相遇的最长时间。
我们最优的策略是把每一只比它前面蚂蚁跑的快的蚂蚁尽量往后放。也就是,对于总路程,除以任意相邻两只蚂蚁后面比前面跑的快的蚂蚁的速度差总和。


<pre name="code" class="cpp">#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 105
#define PI 3.1415926
double a[N];
int main()
{
    int i,n,T;
    double r,tmp;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%lf",&n,&r);
        for(i=0;i<n;i++)
            scanf("%lf",&a[i]);
        tmp=0;
        for(i=1;i<n;i++)
        {
            if(a[i-1]>a[i])
                tmp+=a[i-1]-a[i];
        }
        if(a[n-1]>a[0])
            tmp+=a[n-1]-a[0];
        if(tmp==0)
            printf("Inf\n");
        else
            printf("%.3f\n",PI*2*r/tmp);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值