HDU 3402 Ants run!

Ants run!

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 875    Accepted Submission(s): 311

Problem Description
Professor Yang likes to play with ants when he is free. 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. At first the distances of every two adjacent ants are the same around the boundary of the 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 change the order of the ants to make the game last longer.
 
Input
The first line of the input is T (no more than 100), which stands for the number of test cases you need to solve. Each test case begins with N and R, representing the number of ants participating the game is N ( N <= 100000)and the radius of the circle is R(R <= 100000) 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 these N numbers are positive integer not larger than 1000.
 
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
2 1
1 2
 
Sample Output
Inf
3.142
 
Author
lxhgww
 
Source
 
Recommend
lcy
 
思路:贪心,从小到大排序然后找时间最小的就是答案
因为只有从小到大排序时间是才是最长的
 
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
double PI = 3.1415926 * 2;
int t,n;
double r;
double dis_tance;
double minn;
int map[100010];
int main()
{
    scanf("%d",&t);
    while(t --)
    {
        minn = 100000.00;
        scanf("%d%lf",&n,&r);
        memset(map,0,sizeof(map));
        for(int i = 1;i <= n;i ++)
              scanf("%d",&map[i]);
        if(map[1] == map[n])
            printf("inf\n");
        else
        {
            sort(map + 1,map + n + 1);
            dis_tance = (PI * r) / n;
            for(int i = n;i > 1;i --)
               if(dis_tance / (map[i] - map[i - 1]) < minn)
                  minn = dis_tance / (map[i] - map[i - 1]);
            printf("%.3lf\n",minn);
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/GODLIKEING/p/3334931.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值